/** * Test if left > right. * * @param left first value * @param right second value * @return test result. */ public boolean greaterThan(Object left, Object right) { if ((left == right) || left == null || right == null) { return false; } else { return compare(left, right, ">") > 0; } }
/** * Test if left >= right. * * @param left first value * @param right second value * @return test result. */ public boolean greaterThanOrEqual(Object left, Object right) { if (left == right) { return true; } else if (left == null || right == null) { return false; } else { return compare(left, right, ">=") >= 0; } }
/** * Test if left < right. * * @param left first value * @param right second value * @return test result. */ public boolean lessThan(Object left, Object right) { if ((left == right) || (left == null) || (right == null)) { return false; } else { return compare(left, right, "<") < 0; } }
/** * Test if left <= right. * * @param left first value * @param right second value * @return test result. */ public boolean lessThanOrEqual(Object left, Object right) { if (left == right) { return true; } else if (left == null || right == null) { return false; } else { return compare(left, right, "<=") <= 0; } }
@Override protected int compare(Object left, Object right, String operator) { log.trace("Comparing"); if (left instanceof Collection && (right instanceof String || right instanceof Integer)) { /* * System.out.println("R: " + right.toString()); StringBuilder sb = new StringBuilder(); for( Object strObj : ((Set) left).toArray() ){ * sb.append(strObj.toString()).append("."); } System.out.println("L: " + sb.toString()); */ if (((Collection) left).contains(right)) { return 0; } } return super.compare(left, right, operator); } }
/** * Test if left and right are equal. * * @param left first value * @param right second value * @return test result. */ public boolean equals(Object left, Object right) { if (left == right) { return true; } else if (left == null || right == null) { return false; } else if (left instanceof Boolean || right instanceof Boolean) { return toBoolean(left) == toBoolean(right); } else { return compare(left, right, "==") == 0; } }
/** * Performs a comparison. * * @param left * the left operand * @param right * the right operator * @param operator * the operator * @return {@code -1 if left < right; +1 if left > right; 0 if left == right} * @throws ArithmeticException * if either left or right is null * @since 2.1 */ protected int compare(Object left, Object right, String operator) { if (left != null && right != null) { if ((isNumberable(left) || isFloatingPoint(left)) && NumericalEncoder.isPossiblyEncoded(right.toString())) { long lhs = toLong(left); return compare(toBigDecimal(left), NumericalEncoder.decode(right.toString()), operator); } else if (NumericalEncoder.isPossiblyEncoded(left.toString()) && (isNumberable(right) || isFloatingPoint(right))) { return compare(NumericalEncoder.decode(left.toString()), toBigDecimal(right), operator); } else { return super.compare(left, right, operator); } } throw new ArithmeticException("Object comparison:(" + left + " " + operator + " " + right + ")"); }