1: package ;
2:
3: import ;
4: import ;
5: import ;
6: import ;
7: import ;
8: import ;
9: import ;
10: import ;
11:
12:
17: public abstract class AbstractCompareOperator implements InfixOperator
18: {
19: private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE);
20: private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE);
21:
22: public AbstractCompareOperator()
23: {
24: }
25:
26: public final TypeValuePair evaluate(final FormulaContext context,
27: final TypeValuePair value1,
28: final TypeValuePair value2)
29: throws EvaluationException
30: {
31: final TypeRegistry typeRegistry = context.getTypeRegistry();
32: final Type type1 = value1.getType();
33: final Type type2 = value2.getType();
34: final Object value1Raw = value1.getValue();
35: final Object value2Raw = value2.getValue();
36: if (value1Raw == null || value2Raw == null)
37: {
38: throw new EvaluationException(LibFormulaErrorValue.ERROR_NA_VALUE);
39: }
40:
41: final ExtendedComparator comparator = typeRegistry.getComparator(type1, type2);
42: final Integer result = comparator.compare (type1, value1Raw, type2, value2Raw);
43: if (result == null)
44: {
45: throw new EvaluationException
46: (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
47: }
48:
49: if (evaluate(result.intValue()))
50: {
51: return RETURN_TRUE;
52: }
53: return RETURN_FALSE;
54: }
55:
56: protected abstract boolean evaluate(int compareResult);
57: }