@Override public int getCost() { // Assume the RHS will be evaluated 50% of the time return getLhsExpression().getCost() + getRhsExpression().getCost() / 2; }
/** * Evaluate as a boolean. */ public boolean effectiveBooleanValue(XPathContext c) throws XPathException { return getLhsExpression().effectiveBooleanValue(c) && getRhsExpression().effectiveBooleanValue(c); }
/** * Evaluate as a boolean. */ public boolean effectiveBooleanValue(XPathContext c) throws XPathException { return getLhsExpression().effectiveBooleanValue(c) && getRhsExpression().effectiveBooleanValue(c); }
@Override public int getCost() { // Assume the RHS will be evaluated 50% of the time return getLhsExpression().getCost() + getRhsExpression().getCost() / 2; }
@Override protected Expression preEvaluate() { // If the value can be determined from knowledge of one operand, precompute the result if (Literal.isConstantBoolean(getLhsExpression(), false) || Literal.isConstantBoolean(getRhsExpression(), false)) { // A and false() => false() // false() and B => false() return Literal.makeLiteral(BooleanValue.FALSE, this); } else if (Literal.hasEffectiveBooleanValue(getLhsExpression(), true)) { // true() and B => B return forceToBoolean(getRhsExpression()); } else if (Literal.hasEffectiveBooleanValue(getRhsExpression(), true)) { // A and true() => A return forceToBoolean(getLhsExpression()); } else { return this; } }
@Override protected Expression preEvaluate() { // If the value can be determined from knowledge of one operand, precompute the result if (Literal.isConstantBoolean(getLhsExpression(), false) || Literal.isConstantBoolean(getRhsExpression(), false)) { // A and false() => false() // false() and B => false() return Literal.makeLiteral(BooleanValue.FALSE, this); } else if (Literal.hasEffectiveBooleanValue(getLhsExpression(), true)) { // true() and B => B return forceToBoolean(getRhsExpression()); } else if (Literal.hasEffectiveBooleanValue(getRhsExpression(), true)) { // A and true() => A return forceToBoolean(getLhsExpression()); } else { return this; } }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { AndExpression a2 = new AndExpression(getLhsExpression().copy(rebindings), getRhsExpression().copy(rebindings)); ExpressionTool.copyLocationInfo(this, a2); return a2; }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { AndExpression a2 = new AndExpression(getLhsExpression().copy(rebindings), getRhsExpression().copy(rebindings)); ExpressionTool.copyLocationInfo(this, a2); return a2; }
if ( getRhsExpression() instanceof UserFunctionCall && th.isSubType(getRhsExpression().getItemType(), BuiltInAtomicType.BOOLEAN) && !ExpressionTool.isLoopingSubexpression(this, null)) { Expression cond = Choose.makeConditional( getLhsExpression(), getRhsExpression(), Literal.makeLiteral(BooleanValue.FALSE, this)); ExpressionTool.copyLocationInfo(this, cond); return cond;
if ( getRhsExpression() instanceof UserFunctionCall && th.isSubType(getRhsExpression().getItemType(), BuiltInAtomicType.BOOLEAN) && !ExpressionTool.isLoopingSubexpression(this, null)) { Expression cond = Choose.makeConditional( getLhsExpression(), getRhsExpression(), Literal.makeLiteral(BooleanValue.FALSE, this)); ExpressionTool.copyLocationInfo(this, cond); return cond;
/** * Return the negation of this boolean expression, that is, an expression that returns true * when this expression returns false, and vice versa * * @return the negation of this expression */ public Expression negate() { // Apply de Morgan's laws // not(A and B) ==> not(A) or not(B) Expression not0 = SystemFunction.makeCall("not", getRetainedStaticContext(), getLhsExpression()); Expression not1 = SystemFunction.makeCall("not", getRetainedStaticContext(), getRhsExpression()); return new OrExpression(not0, not1); }
/** * Return the negation of this boolean expression, that is, an expression that returns true * when this expression returns false, and vice versa * * @return the negation of this expression */ public Expression negate() { // Apply de Morgan's laws // not(A and B) ==> not(A) or not(B) Expression not0 = SystemFunction.makeCall("not", getRetainedStaticContext(), getLhsExpression()); Expression not1 = SystemFunction.makeCall("not", getRetainedStaticContext(), getRhsExpression()); return new OrExpression(not0, not1); }