use of org.drools.model.constraints.AndConstraints in project drools by kiegroup.
the class BruteForceEngine method match.
private boolean match(Constraint constraint, TupleHandle tuple) {
switch(constraint.getType()) {
case SINGLE:
SingleConstraint singleCon = (SingleConstraint) constraint;
Variable[] vars = singleCon.getVariables();
switch(vars.length) {
case 0:
try {
return singleCon.getPredicate().test();
} catch (Exception e) {
throw new RuntimeException(e);
}
case 1:
Object obj = tuple.get(vars[0]);
try {
return singleCon.getPredicate().test(obj);
} catch (Exception e) {
throw new RuntimeException(e);
}
case 2:
Object obj1 = tuple.get(vars[0]);
Object obj2 = tuple.get(vars[1]);
try {
return singleCon.getPredicate().test(obj1, obj2);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
case AND:
AndConstraints andCon = (AndConstraints) constraint;
return andCon.getChildren().stream().allMatch(con -> match(con, tuple));
case OR:
OrConstraints orCon = (OrConstraints) constraint;
return orCon.getChildren().stream().anyMatch(con -> match(con, tuple));
}
return false;
}
Aggregations