@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; }
@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; }
@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 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); } } }
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; }
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; }
/** * 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 void meet(If node) throws RDFHandlerException { Resource currentSubj = subject; flushPendingStatement(); handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, SP.IF)); predicate = SP.ARG1_PROPERTY; node.getCondition().visit(this); predicate = SP.ARG2_PROPERTY; node.getResult().visit(this); predicate = SP.ARG3_PROPERTY; node.getAlternative().visit(this); subject = currentSubj; predicate = null; }