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); } } }
@Override public void visit(ComparisonNode comparisonNode) { comparisonNode.getLHS().accept(this); comparisonNode.getRHS().accept(this); }
public void visit(ComparisonNode node) { node.getLHS().accept(this); node.getRHS().accept(this); }
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; } }