use of org.drools.core.base.evaluators.Operator in project drools by kiegroup.
the class MVELDumper method processRestriction.
public String processRestriction(MVELDumperContext 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.core.base.evaluators.Operator in project drools by kiegroup.
the class RuleModelDRLPersistenceImpl method findOperator.
private static String findOperator(String expr) {
// only need to try to find the first operator before the ConnectiveConstraint separator.
if (expr.contains("&&")) {
expr = expr.substring(0, expr.indexOf("&&")).trim();
}
if (expr.contains("||")) {
expr = expr.substring(0, expr.indexOf("||")).trim();
}
final Set<String> potentialOperators = new HashSet<String>();
for (Operator op : Operator.getAllOperators()) {
String opString = op.getOperatorString();
if (op.isNegated()) {
if (expr.contains(" not " + opString)) {
return "not " + opString;
}
}
int opPos = expr.indexOf(opString);
if (opPos >= 0 && !isInQuote(expr, opPos) && !(Character.isLetter(opString.charAt(0)) && (expr.length() == opPos + opString.length() || Character.isLetter(expr.charAt(opPos + opString.length())) || (opPos > 0 && Character.isLetter(expr.charAt(opPos - 1)))))) {
potentialOperators.add(opString);
}
}
String operator = "";
if (!potentialOperators.isEmpty()) {
for (String potentialOperator : potentialOperators) {
if (potentialOperator.length() > operator.length()) {
operator = potentialOperator;
}
}
}
if (!operator.isEmpty()) {
return operator;
}
if (expr.contains(" not in ")) {
return " not in ";
}
if (expr.contains(" in ")) {
return " in ";
}
return null;
}
use of org.drools.core.base.evaluators.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);
}
}
Aggregations