public List<Value> evaluate(List<Value> values, List<Value> results) {
for (Value value : values) {
if (value.getValueType() == Value.TYPE.ARRAY) {
for (int j = 0; j < value.size(); j++) {
Value checkElement = value.get(j);
if (checkElement.getValueType() == Value.TYPE.OBJECT) {
boolean expressionValid = true;
for (ExpressionPredicateCondition condition : conditions) {
if (condition instanceof OperatorExpressionPredicateCondition) {
OperatorExpressionPredicateCondition operatorCondition = (OperatorExpressionPredicateCondition) condition;
Value checkValue = checkElement.get(operatorCondition.getAttribute());
if (checkValue == null) {
expressionValid = false;
break;
}
ExpressionPredicateOperator expressionConditionOperator = operatorCondition.getOperator();
if (expressionConditionOperator.equals(ExpressionPredicateOperator.NOT_NULL)) {
if (checkValue.isNull()) {
expressionValid = false;
break;
}
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.EQUAL)) {
if (!checkValue.equals(operatorCondition.value)) {
expressionValid = false;
break;
}
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.LESS)) {
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.GREATER)) {
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.LESS_EQUAL)) {
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.GREATER_EQUAL)) {
}
} else if (condition instanceof FunctionExpressionPredicateCondition) {
FunctionExpressionPredicateCondition functionCondition = (FunctionExpressionPredicateCondition) condition;
String functionName = functionCondition.getFunctionName();
FunctionArgument[] funtionArguments = functionCondition.getArguments();
if(functionName.equals("regex")) {
RegexFunction regexFunction = new RegexFunction();
Value result = regexFunction.evaluate(funtionArguments, checkElement);
if(result == null) {
expressionValid = false;
break;
}
}
}
}
if (expressionValid) {
results.add(checkElement);
}
}
}
} else {
if(value.getValueType() == Value.TYPE.OBJECT) {
boolean expressionValid = true;
for (ExpressionPredicateCondition condition : conditions) {
if (condition instanceof OperatorExpressionPredicateCondition) {
OperatorExpressionPredicateCondition operatorCondition = (OperatorExpressionPredicateCondition) condition;
Value checkValue = value.get(operatorCondition.getAttribute());
if (checkValue == null) {
expressionValid = false;
break;
}
ExpressionPredicateOperator expressionConditionOperator = operatorCondition.getOperator();
if (expressionConditionOperator.equals(ExpressionPredicateOperator.NOT_NULL)) {
if (checkValue.isNull()) {
expressionValid = false;
break;
}
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.EQUAL)) {
if (!checkValue.equals(operatorCondition.value)) {
expressionValid = false;
break;
}
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.LESS)) {
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.GREATER)) {
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.LESS_EQUAL)) {
} else if (expressionConditionOperator.equals(ExpressionPredicateOperator.GREATER_EQUAL)) {
}
} else if (condition instanceof FunctionExpressionPredicateCondition) {
FunctionExpressionPredicateCondition functionCondition = (FunctionExpressionPredicateCondition) condition;
String functionName = functionCondition.getFunctionName();
FunctionArgument[] funtionArguments = functionCondition.getArguments();
if(functionName.equals("regex")) {
RegexFunction regexFunction = new RegexFunction();
Value result = regexFunction.evaluate(funtionArguments, value);
if(result != null) {
results.add(value);
}
}
}