use of org.drools.drl.parser.impl.Operator in project drools by kiegroup.
the class ExprConstraintDescrVisitor method visit.
private void visit(RelationalExprDescr descr) {
int currentOrderNumber = orderNumber.next();
String fieldName = visit(descr.getLeft());
Operator operator = Operator.determineOperator(descr.getOperator(), descr.isNegated());
String value = visit(descr.getRight());
setField(descr, fieldName);
if (isAVariableRestriction(value)) {
createVariableRestriction(currentOrderNumber, value, operator);
} else {
createRestriction(currentOrderNumber, value, operator);
}
}
use of org.drools.drl.parser.impl.Operator in project drools by kiegroup.
the class DescrDumper method processRestriction.
public String processRestriction(DumperContext context, String left, OperatorDescr operator, String right) {
StringBuilder sbuilder = new StringBuilder();
Operator op = Operator.determineOperator(operator.getOperator(), operator.isNegated());
if (op == Operator.determineOperator("memberOf", operator.isNegated())) {
int lastAndPos = left.lastIndexOf("&&");
if (lastAndPos > 0) {
sbuilder.append(left.substring(0, lastAndPos).trim()).append(" && ");
left = left.substring(lastAndPos + 2).trim();
}
sbuilder.append(evaluatorPrefix(operator.isNegated())).append(right).append(" contains ").append(left).append(evaluatorSufix(operator.isNegated()));
} else if (op == Operator.determineOperator("contains", operator.isNegated())) {
sbuilder.append(evaluatorPrefix(operator.isNegated())).append(left).append(" contains ").append(right).append(evaluatorSufix(operator.isNegated()));
} else if (op == Operator.determineOperator("excludes", operator.isNegated())) {
sbuilder.append(evaluatorPrefix(!operator.isNegated())).append(left).append(" contains ").append(right).append(evaluatorSufix(!operator.isNegated()));
} else if (op == Operator.determineOperator("matches", operator.isNegated())) {
sbuilder.append(evaluatorPrefix(operator.isNegated())).append(left).append(" ~= ").append(right).append(evaluatorSufix(operator.isNegated()));
} else if (lookupBasicOperator(operator.getOperator())) {
if (operator.getOperator().equals("instanceof")) {
context.addInferredCast(left, right);
}
rewriteBasicOperator(sbuilder, left, operator, right);
} else {
// rewrite operator as a function call
rewriteOperator(context, sbuilder, left, operator, right);
}
return sbuilder.toString();
}
use of org.drools.drl.parser.impl.Operator in project drools by kiegroup.
the class BaseBetaConstraintsTest method getCheeseTypeConstraint.
protected BetaNodeFieldConstraint getCheeseTypeConstraint(final String identifier, Operator operator) {
if (useLambdaConstraint) {
Pattern pattern = new Pattern(0, new ClassObjectType(Cheese.class));
Predicate1<Cheese> predicate;
if (operator == Operator.BuiltInOperator.EQUAL.getOperator()) {
predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.areNullSafeEquals(_this.getType(), identifier));
} else if (operator == Operator.BuiltInOperator.NOT_EQUAL.getOperator()) {
predicate = new Predicate1.Impl<Cheese>(_this -> !EvaluationUtil.areNullSafeEquals(_this.getType(), identifier));
} else if (operator == Operator.BuiltInOperator.GREATER.getOperator()) {
predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.greaterThan(_this.getType(), identifier));
} else if (operator == Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator()) {
predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.greaterOrEqual(_this.getType(), identifier));
} else if (operator == Operator.BuiltInOperator.LESS.getOperator()) {
predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.lessThan(_this.getType(), identifier));
} else if (operator == Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator()) {
predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.lessOrEqual(_this.getType(), identifier));
} else {
throw new RuntimeException(operator + " is not supported");
}
return LambdaConstraintTestUtil.createLambdaConstraint1(Cheese.class, pattern, predicate, null);
} else {
ClassFieldAccessorStore store = new ClassFieldAccessorStore();
store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
store.setEagerWire(true);
InternalReadAccessor extractor = store.getReader(Cheese.class, "type");
Declaration declaration = new Declaration(identifier, extractor, new Pattern(0, new ClassObjectType(Cheese.class)));
String expression = "type " + operator.getOperatorString() + " " + identifier;
return new MVELConstraintTestUtil(expression, operator.getOperatorString(), declaration, extractor);
}
}
Aggregations