Search in sources :

Example 1 with NumericFieldValue

use of com.yahoo.document.datatypes.NumericFieldValue in project vespa by vespa-engine.

the class IfThenExpression method isTrue.

private static boolean isTrue(FieldValue lhs, Comparator cmp, FieldValue rhs) {
    int res;
    if (lhs instanceof NumericFieldValue && rhs instanceof NumericFieldValue) {
        BigDecimal lhsVal = ArithmeticExpression.asBigDecimal((NumericFieldValue) lhs);
        BigDecimal rhsVal = ArithmeticExpression.asBigDecimal((NumericFieldValue) rhs);
        res = lhsVal.compareTo(rhsVal);
    } else {
        res = lhs.compareTo(rhs);
    }
    switch(cmp) {
        case EQ:
            return res == 0;
        case NE:
            return res != 0;
        case GT:
            return res > 0;
        case GE:
            return res >= 0;
        case LT:
            return res < 0;
        case LE:
            return res <= 0;
        default:
            throw new UnsupportedOperationException(cmp.toString());
    }
}
Also used : NumericFieldValue(com.yahoo.document.datatypes.NumericFieldValue) BigDecimal(java.math.BigDecimal)

Aggregations

NumericFieldValue (com.yahoo.document.datatypes.NumericFieldValue)1 BigDecimal (java.math.BigDecimal)1