/** * Current implementation of comparison processor accept numbers and dates. */ @Override public boolean acceptValue(Object value) { if (Types.isNumber(value)) { return true; } if (Types.isDate(value)) { return true; } return false; } }
/** * Check operand format compatibility against value counterpart. * * @param value content value to validate operand against, * @param operand formatted string operand. * @return true if <code>operand</code> format is compatible with requested <code>value</code>. */ public static boolean isValid(Object value, String operand) { if (operand == null) { // validation is enacted only for operator processors that do not accept null operand // so always return false return false; } if (Types.isBoolean(value)) { return BOOLEAN_PATTERN.matcher(operand).matches(); } if (Types.isNumber(value)) { return NUMBER_PATTERN.matcher(operand).matches(); } if (Types.isDate(value)) { return DATE_PATTERN.matcher(operand).matches(); } return true; } }
return ""; if(Types.isDate(t)) { return new Date();
if (Types.isDate(value)) { DateFormat df = scriptDateFormat.get(); if (df == null) {
@Override public boolean evaluate(Object value, String operand) { if (Types.isNumber(value)) { Converter converter = ConverterRegistry.getConverter(); Double doubleValue = ((Number) value).doubleValue(); Double doubleOperand = 0.0; if (value instanceof Float) { // converting float to double may change last decimal digits // we need to ensure both value and operand undergo the same treatment, i.e. use Float#doubleValue() method // for both // for example float number 1.23F is converted to double to 1.2300000190734863 // if we convert string "1.23" to double we have 1.23 != 1.2300000190734863 Float floatOperand = converter.asObject(operand, Float.class); doubleOperand = floatOperand.doubleValue(); } else { doubleOperand = converter.asObject(operand, Double.class); } return compare(doubleValue, doubleOperand); } if (Types.isDate(value)) { Date dateValue = (Date) value; Date dateOperand = Dates.parse(operand); return compare(dateValue, dateOperand); } return false; }
/** * Test if type is like a primitive? Return true only if given type is a number, boolean, enumeration, character or * string. * * @param t type to test. * @return true if this type is like a primitive. */ public static boolean isPrimitiveLike(Type t) { if(isNumber(t)) { return true; } if(isBoolean(t)) { return true; } if(isEnum(t)) { return true; } if(isCharacter(t)) { return true; } if(isDate(t)) { return true; } if(t == String.class) { return true; } return false; }