@Override public boolean toBoolean(Object val) { return delegate.toBoolean(val); }
/** * some of our nodes evaluate to a collection of matches. Coerce this collection to true or false based on the size of matches */ @Override public boolean toBoolean(Object val) { if (val instanceof Collection) { return !((Collection) val).isEmpty(); } return super.toBoolean(val); }
/** * Test if left and right are equal. * * @param left first value * @param right second value * @return test result. */ public boolean equals(Object left, Object right) { if (left == right) { return true; } else if (left == null || right == null) { return false; } else if (left instanceof Boolean || right instanceof Boolean) { return toBoolean(left) == toBoolean(right); } else { return compare(left, right, "==") == 0; } }
/** {@inheritDoc} */ public Object visit(ASTNotNode node, Object data) { Object val = node.jjtGetChild(0).jjtAccept(this, data); return arithmetic.toBoolean(val) ? Boolean.FALSE : Boolean.TRUE; }
/** {@inheritDoc} */ public Object visit(ASTTernaryNode node, Object data) { Object condition = node.jjtGetChild(0).jjtAccept(this, data); if (node.jjtGetNumChildren() == 3) { if (condition != null && arithmetic.toBoolean(condition)) { return node.jjtGetChild(1).jjtAccept(this, data); } else { return node.jjtGetChild(2).jjtAccept(this, data); } } if (condition != null && arithmetic.toBoolean(condition)) { return condition; } else { return node.jjtGetChild(1).jjtAccept(this, data); } }
/** {@inheritDoc} */ public Object visit(ASTOrNode node, Object data) { Object left = node.jjtGetChild(0).jjtAccept(this, data); try { boolean leftValue = arithmetic.toBoolean(left); if (leftValue) { return Boolean.TRUE; } } catch (ArithmeticException xrt) { throw new JexlException(node.jjtGetChild(0), "boolean coercion error", xrt); } Object right = node.jjtGetChild(1).jjtAccept(this, data); try { boolean rightValue = arithmetic.toBoolean(right); if (rightValue) { return Boolean.TRUE; } } catch (ArithmeticException xrt) { throw new JexlException(node.jjtGetChild(1), "boolean coercion error", xrt); } return Boolean.FALSE; }
/** {@inheritDoc} */ public Object visit(ASTAndNode node, Object data) { Object left = node.jjtGetChild(0).jjtAccept(this, data); try { boolean leftValue = arithmetic.toBoolean(left); if (!leftValue) { return Boolean.FALSE; } } catch (RuntimeException xrt) { throw new JexlException(node.jjtGetChild(0), "boolean coercion error", xrt); } Object right = node.jjtGetChild(1).jjtAccept(this, data); try { boolean rightValue = arithmetic.toBoolean(right); if (!rightValue) { return Boolean.FALSE; } } catch (ArithmeticException xrt) { throw new JexlException(node.jjtGetChild(1), "boolean coercion error", xrt); } return Boolean.TRUE; }
JexlMethod vm = uberspect.getMethod(right, "contains", argv, node); if (vm != null) { return arithmetic.toBoolean(vm.invoke(right, argv)) ? Boolean.TRUE : Boolean.FALSE; } else if (arithmetic.narrowArguments(argv)) { vm = uberspect.getMethod(right, "contains", argv, node); if (vm != null) { return arithmetic.toBoolean(vm.invoke(right, argv)) ? Boolean.TRUE : Boolean.FALSE;
JexlMethod vm = uberspect.getMethod(right, "contains", argv, node); if (vm != null) { return arithmetic.toBoolean(vm.invoke(right, argv)) ? Boolean.FALSE : Boolean.TRUE; } else if (arithmetic.narrowArguments(argv)) { vm = uberspect.getMethod(right, "contains", argv, node); if (vm != null) { return arithmetic.toBoolean(vm.invoke(right, argv)) ? Boolean.FALSE : Boolean.TRUE;
/** {@inheritDoc} */ public Object visit(ASTWhileStatement node, Object data) { Object result = null; /* first objectNode is the expression */ Node expressionNode = node.jjtGetChild(0); while (arithmetic.toBoolean(expressionNode.jjtAccept(this, data))) { if (isCancelled()) { throw new JexlException.Cancel(node); } // execute statement if (node.jjtGetNumChildren() > 1) { result = node.jjtGetChild(1).jjtAccept(this, data); } } return result; }
/** {@inheritDoc} */ public Object visit(ASTIfStatement node, Object data) { int n = 0; try { Object result = null; /* first objectNode is the condition */ Object expression = node.jjtGetChild(0).jjtAccept(this, data); if (arithmetic.toBoolean(expression)) { // first objectNode is true statement n = 1; result = node.jjtGetChild(1).jjtAccept(this, data); } else { // if there is a false, execute it. false statement is the second // objectNode if (node.jjtGetNumChildren() == 3) { n = 2; result = node.jjtGetChild(2).jjtAccept(this, data); } } return result; } catch (JexlException error) { throw error; } catch (ArithmeticException xrt) { throw new JexlException(node.jjtGetChild(n), "if error", xrt); } }