use of com.tvd12.dahlia.math.Operation in project dahlia by youngmonkeys.
the class QueryToPredicate method toDefaultPredicate.
protected Predicate<EzyObject> toDefaultPredicate(EzyObject query) {
for (Entry kv : query.entrySet()) {
String field = null;
Object value = kv.getValue();
String fieldOrOperation = (String) kv.getKey();
Operation operation = Operation.valueOfKeyword(fieldOrOperation);
if (operation != null) {
EzyObject oValue = (EzyObject) value;
for (Entry e : oValue.entrySet()) {
field = (String) e.getKey();
value = e.getValue();
break;
}
} else if (value instanceof EzyObject) {
EzyObject oValue = (EzyObject) value;
for (Entry e : oValue.entrySet()) {
String keyword = (String) e.getKey();
operation = Operation.valueOfKeyword(keyword);
value = e.getValue();
break;
}
} else {
field = fieldOrOperation;
operation = Operation.EQ;
}
String qField = field;
Object qValue = value;
Operation qOperation = operation;
return record -> {
Object rValue = record.get(qField);
int compareResult = compareValue(rValue, qValue);
if (qOperation == Operation.GT)
return compareResult > 0;
if (qOperation == Operation.GTE)
return compareResult >= 0;
if (qOperation == Operation.LT)
return compareResult < 0;
if (qOperation == Operation.LTE)
return compareResult <= 0;
if (qOperation == Operation.NEQ)
return compareResult != 0;
return compareResult == 0;
};
}
return record -> false;
}
Aggregations