public void visit(ComparisonNode node) { if (state != null) { throw new IllegalArgumentException("Comparison cannot be done within now expression"); } if (!hasNow(node)) { return; } state = new BuildState(); node.getLHS().accept(this); node.getRHS().accept(this); if (!">".equals(node.getOperator())) { throw new IllegalArgumentException("Comparison operator '" + node.getOperator() + "' is not supported"); } if (!(node.getLHS() instanceof AttributeNode)) { throw new IllegalArgumentException("Left hand side of comparison must be a document field"); } state.comparison = node; if (state.attribute != null && state.comparison != null && (state.arithmetic != null || state.now != null)) { NowQueryExpression expression = new NowQueryExpression(state.attribute, state.comparison, state.arithmetic); expressionMap.put(expression.getDocumentType(), expression); state = null; } }
public BucketSet getBucketSet(BucketIdFactory factory) { if (operator.equals("==") || operator.equals("=")) { if (lhs instanceof IdNode && rhs instanceof LiteralNode) { return compare(factory, (IdNode)lhs, (LiteralNode)rhs, operator); } else if (rhs instanceof IdNode && lhs instanceof LiteralNode) { return compare(factory, (IdNode)rhs, (LiteralNode)lhs, operator); } else if (lhs instanceof SearchColumnNode && rhs instanceof LiteralNode) { return compare(factory, (SearchColumnNode)lhs, (LiteralNode)rhs); } else if (rhs instanceof SearchColumnNode && lhs instanceof LiteralNode) { return compare(factory, (SearchColumnNode)rhs, (LiteralNode)lhs); } } return null; }
public Object evaluate(Context context) { Object oLeft = lhs.evaluate(context); Object oRight = rhs.evaluate(context); if (oLeft == null || oRight == null) { return evaluateWithAtLeastOneNullSide(oLeft, oRight); } if (oLeft == Result.INVALID || oRight == Result.INVALID) { return new ResultList(Result.INVALID); } if (oLeft instanceof AttributeNode.VariableValueList && oRight instanceof AttributeNode.VariableValueList) { if (operator.equals("==")) { return evaluateListsTrue((AttributeNode.VariableValueList)oLeft, (AttributeNode.VariableValueList)oRight); } else if (operator.equals("!=")) { return evaluateListsFalse((AttributeNode.VariableValueList)oLeft, (AttributeNode.VariableValueList)oRight); } else { return new ResultList(Result.INVALID); } } else if (oLeft instanceof AttributeNode.VariableValueList) { return evaluateListAndSingle((AttributeNode.VariableValueList)oLeft, oRight); } else if (oRight instanceof AttributeNode.VariableValueList) { return evaluateListAndSingle((AttributeNode.VariableValueList)oRight, oLeft); } return new ResultList(evaluateBool(oLeft, oRight)); }
/** * Evaluate this expression on two operands, given that they are not invalid. * * @param lhs Left hand side of operation. * @param rhs Right hand side of operation. * @return The evaluation result. */ private Result evaluateBool(Object lhs, Object rhs) { if (operator.equals("==")) { return evaluateEquals(lhs, rhs); } else if (operator.equals("!=")) { return Result.invert(evaluateEquals(lhs, rhs)); } else if (operator.equals("<") || operator.equals("<=") || operator.equals(">") || operator.equals(">=")) { return evaluateNumber(lhs, rhs); } else if (operator.equals("=~") || operator.equals("=")) { return evaluateString(lhs, rhs); } throw new IllegalStateException("Comparison operator '" + operator + "' is not supported."); }
public Number evaluate(Document doc, Map<String, Object> variables) { Context context = new Context(new DocumentPut(doc)); context.setVariables(variables); try { Object o = comparison.getLHS().evaluate(context); if (Double.isInfinite(((Number)o).doubleValue())) { throw new IllegalArgumentException("Expression evaluated to an infinite number"); } return ((Number)o).doubleValue(); } catch (ArithmeticException e) { throw new IllegalArgumentException("Arithmetic exception " + e.getMessage(), e); } } }
IntegerParser v = new IntegerParser(); if (v.parse(op.getRemaining())) { node = new ComparisonNode(id.getId(), op.getOperator(), v.getValue()); retval = true; StringParser v = new StringParser(); if (v.parse(op.getRemaining())) { node = new ComparisonNode(id.getId(), op.getOperator(), v.getValue()); retval = true;
public ResultList evaluateListsFalse(AttributeNode.VariableValueList lhs, AttributeNode.VariableValueList rhs) { ResultList lst = evaluateListsTrue(lhs, rhs); if (lst.toResult() == Result.TRUE) { return new ResultList(Result.FALSE); } else if (lst.toResult() == Result.FALSE) { return new ResultList(Result.TRUE); } else { return lst; } }
public ResultList evaluateListAndSingle(AttributeNode.VariableValueList lhs, Object rhs) { if (rhs == null && lhs == null) { return new ResultList(Result.TRUE); } if (rhs == null || lhs == null) { return new ResultList(Result.FALSE); } ResultList retVal = new ResultList(); for (int i = 0; i < lhs.size(); i++) { Result result = evaluateBool(lhs.get(i).getValue(), rhs); retVal.add((FieldPathIteratorHandler.VariableMap)lhs.get(i).getVariables().clone(), result); } return retVal; }
public ResultList evaluateListsTrue(AttributeNode.VariableValueList lhs, AttributeNode.VariableValueList rhs) { if (lhs.size() != rhs.size()) { return new ResultList(Result.FALSE); } for (int i = 0; i < lhs.size(); i++) { if (!lhs.get(i).getVariables().equals(rhs.get(i).getVariables())) { return new ResultList(Result.FALSE); } if (evaluateEquals(lhs.get(i).getValue(), rhs.get(i).getValue()) == Result.FALSE) { return new ResultList(Result.FALSE); } } return new ResultList(Result.TRUE); }
{if ("" != null) return rhs != null ? new ComparisonNode(lhs, op, rhs) : lhs;} throw new IllegalStateException ("Missing return statement in function");