@Override public boolean equals(Object other) { if (other instanceof If) { If o = (If)other; boolean equal = condition.equals(o.getCondition()); if (!equal) { return equal; } equal = (result == null) ? o.getResult() == null : result.equals(o.getResult()); if (!equal) { return equal; } equal = (alternative == null) ? o.getAlternative() == null : alternative.equals(o.getAlternative()); return equal; } return false; }
public If(ValueExpr condition, ValueExpr result, ValueExpr alternative) { setCondition(condition); setResult(result); setAlternative(alternative); }
public If(ValueExpr condition, ValueExpr result) { setCondition(condition); setResult(result); }
@Override public void meet(If node) { super.meet(node); if (isConstant(node.getCondition())) { try { if (strategy.isTrue(node.getCondition(), EmptyBindingSet.getInstance())) { node.replaceWith(node.getResult()); } else { node.replaceWith(node.getAlternative()); } } catch (ValueExprEvaluationException e) { logger.debug("Failed to evaluate UnaryValueOperator with a constant argument", e); } catch (QueryEvaluationException e) { logger.error("Query evaluation exception caught", e); } } }
@Override public If visit(ASTIf node, Object data) throws VisitorException { If result = null; if (node.jjtGetNumChildren() < 3) { throw new VisitorException("IF construction missing required number of arguments"); } ValueExpr condition = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null); ValueExpr resultExpr = (ValueExpr)node.jjtGetChild(1).jjtAccept(this, null); ValueExpr alternative = (ValueExpr)node.jjtGetChild(2).jjtAccept(this, null); result = new If(condition, resultExpr, alternative); return result; }
public If(ValueExpr condition) { setCondition(condition); }
@Override public void meet(If node) { super.meet(node); if (isConstant(node.getCondition())) { try { if (strategy.isTrue(node.getCondition(), EmptyBindingSet.getInstance())) { node.replaceWith(node.getResult()); } else { node.replaceWith(node.getAlternative()); } } catch (ValueExprEvaluationException e) { logger.debug("Failed to evaluate UnaryValueOperator with a constant argument", e); } catch (QueryEvaluationException e) { logger.error("Query evaluation exception caught", e); } } }
@Override public If visit(ASTIf node, Object data) throws VisitorException { If result = null; if (node.jjtGetNumChildren() < 3) { throw new VisitorException("IF construction missing required number of arguments"); } ValueExpr condition = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null); ValueExpr resultExpr = (ValueExpr)node.jjtGetChild(1).jjtAccept(this, null); ValueExpr alternative = (ValueExpr)node.jjtGetChild(2).jjtAccept(this, null); result = new If(condition, resultExpr, alternative); return result; }
public If(ValueExpr condition, ValueExpr result) { setCondition(condition); setResult(result); }
public If(ValueExpr condition) { setCondition(condition); }
@Override public boolean equals(Object other) { if (other instanceof If) { If o = (If)other; boolean equal = condition.equals(o.getCondition()); if (!equal) { return equal; } equal = (result == null) ? o.getResult() == null : result.equals(o.getResult()); if (!equal) { return equal; } equal = (alternative == null) ? o.getAlternative() == null : alternative.equals(o.getAlternative()); return equal; } return false; }
public If(ValueExpr condition, ValueExpr result, ValueExpr alternative) { setCondition(condition); setResult(result); setAlternative(alternative); }
@Override public If visit(ASTIf node, Object data) throws VisitorException { If result = null; if (node.jjtGetNumChildren() < 3) { throw new VisitorException("IF construction missing required number of arguments"); } ValueExpr condition = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null); ValueExpr resultExpr = (ValueExpr)node.jjtGetChild(1).jjtAccept(this, null); ValueExpr alternative = (ValueExpr)node.jjtGetChild(2).jjtAccept(this, null); result = new If(condition, resultExpr, alternative); return result; }
public Value evaluate(If node, BindingSet bindings) throws QueryEvaluationException { Value result = null; boolean conditionIsTrue; try { Value value = evaluate(node.getCondition(), bindings); conditionIsTrue = QueryEvaluationUtil.getEffectiveBooleanValue(value); } catch (ValueExprEvaluationException e) { // in case of type error, if-construction should result in empty // binding. return null; } if (conditionIsTrue) { result = evaluate(node.getResult(), bindings); } else { result = evaluate(node.getAlternative(), bindings); } return result; }
@Override public void replaceChildNode(QueryModelNode current, QueryModelNode replacement) { if (condition == current) { setCondition((ValueExpr)replacement); } else if (result == current) { setResult((ValueExpr)replacement); } else if (alternative == current) { setAlternative((ValueExpr)replacement); } else { super.replaceChildNode(current, replacement); } }
String.format("Invalid number of arguments for function: %s", func)); expr = new If(args.get(0), args.get(1), args.get(2));
public Value evaluate(If node, BindingSet bindings) throws QueryEvaluationException { Value result = null; boolean conditionIsTrue; try { Value value = evaluate(node.getCondition(), bindings); conditionIsTrue = QueryEvaluationUtil.getEffectiveBooleanValue(value); } catch (ValueExprEvaluationException e) { // in case of type error, if-construction should result in empty // binding. return null; } if (conditionIsTrue) { result = evaluate(node.getResult(), bindings); } else { result = evaluate(node.getAlternative(), bindings); } return result; }
@Override public void replaceChildNode(QueryModelNode current, QueryModelNode replacement) { if (condition == current) { setCondition((ValueExpr)replacement); } else if (result == current) { setResult((ValueExpr)replacement); } else if (alternative == current) { setAlternative((ValueExpr)replacement); } else { super.replaceChildNode(current, replacement); } }
/** * Evaluate an {@link If} node * @param node the node to evaluate * @param bindings the set of named value bindings * @return * @throws QueryEvaluationException */ private Value evaluate(If node, BindingSet bindings) throws QueryEvaluationException { Value result; boolean conditionIsTrue; try { Value value = evaluate(node.getCondition(), bindings); conditionIsTrue = QueryEvaluationUtil.getEffectiveBooleanValue(value); } catch (ValueExprEvaluationException e) { // in case of type error, if-construction should result in empty // binding. return null; } if (conditionIsTrue) { result = evaluate(node.getResult(), bindings); } else { result = evaluate(node.getAlternative(), bindings); } return result; }
@Override public If clone() { If clone = (If)super.clone(); clone.setCondition(condition.clone()); if (result != null) { clone.setResult(result.clone()); } if (alternative != null) { clone.setAlternative(alternative.clone()); } return clone; }