Advertisement
tezuka777

weirest shit

Sep 30th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. public boolean violatesProfileConstraint(Employee employee, int shiftId) {
  2.     List<RawProfileConstraint> rawProfileConstraintList = shiftMapper.getAssociatedProfile(shiftId);
  3.     RawEmployee rawEmp = employee.getRawEmployee();
  4.    
  5.     boolean result = true;
  6.     for (RawProfileConstraint rpc : rawProfileConstraintList) {
  7.         try {
  8.             Field tempField = rawEmp.getClass().getDeclaredField(rpc.getField());
  9.             tempField.setAccessible(true);
  10.             Object fieldNameValue = tempField.get(rawEmp);
  11.  
  12.             Field tempField2 = rawEmp.getClass().getDeclaredField(rpc.getOperator());
  13.             tempField2.setAccessible(true);
  14.             Object operator = tempField2.get(rawEmp);
  15.  
  16.             if (tempField.getType().isAssignableFrom(Number.class)) {
  17.                 float num1 = (float) fieldNameValue;
  18.                 float constraintVal = Float.valueOf(rpc.getValue());
  19.  
  20.                 if (rpc.getOperator().equals("gt")) {
  21.                     result = (num1 > constraintVal);
  22.                 } else if (rpc.getOperator().equals("equal")) {
  23.                     result = (num1 == constraintVal);
  24.                 } else if (rpc.getOperator().equals("lt")) {
  25.                     result = (num1 < constraintVal);
  26.                 }
  27.             } else if (tempField.getType().isAssignableFrom(String.class)) {
  28.                 String string1 = fieldNameValue.toString();
  29.                 String constraintVal = rpc.getValue();
  30.                 if (rpc.getOperator().equals("equal")) {
  31.                     result = string1.equals(constraintVal);
  32.                 } else if (rpc.getOperator().equals("equal")) {
  33.                     result = !string1.equals(constraintVal);
  34.                 }
  35.             } else if (tempField.getType().isAssignableFrom(Date.class)) {
  36.                 DateFormat df = new SimpleDateFormat();
  37.                 Date date1 = (Date) fieldNameValue;
  38.                 Date constraintVal = (Date) df.parse(rpc.getValue());
  39.                 if (rpc.getOperator().equals("isBefore")) {
  40.                     result = (date1.before(constraintVal));
  41.                 } else if (rpc.getOperator().equals("equal")) {
  42.                     result = (date1.equals(constraintVal));
  43.                 } else if (rpc.getOperator().equals("isAfter")) {
  44.                     result = (date1.after(constraintVal));
  45.                 } else if (rpc.getOperator().equals("not equal")) {
  46.                     result = !(date1.equals(constraintVal));
  47.                 }
  48.             }
  49.             //&& f.getName().equals(rpc.getOperator()) && f.getName().equals(rpc.getValue())
  50.         } catch (Exception e) {
  51.             //
  52.         }
  53.     }
  54.     return result;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement