/** * Generate an 'and' tree over a set of expressions * @param exprs the expressions to be "and'ed" together * @return the root of the new expression tree */ public static Expression distribute(Collection<Expression> exprs) { Expression result = null; if(exprs != null) { boolean first = true; for(Expression e: exprs) { if(first){ first = false; result = e; } else { result = new AndExpression(result,e); } } } return result; } }
/** * Generate an 'and' tree over a set of expressions * @param exprs the expressions to be "and'ed" together * @return the root of the new expression tree */ public static Expression distribute(Collection<Expression> exprs) { Expression result = null; if(exprs != null) { boolean first = true; for(Expression e: exprs) { if(first){ first = false; result = e; } else { result = new AndExpression(result,e); } } } return result; } }
Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo);
Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo);
/** * Recursive method to make a list of expressions into a AndExpression * * @param list of Expression * @return And Expression of list of expressions */ private Expression makeAndCondition(List<Expression> list) { if (list.size() == 1) { return list.get(0); } else { return new AndExpression(list.get(0), makeAndCondition(list.subList(1, list.size()))); } }
/** * Recursive method to make a list of expressions into a AndExpression * * @param list of Expression * @return And Expression of list of expressions */ private Expression makeAndCondition(List<Expression> list) { if (list.size() == 1) { return list.get(0); } else { return new AndExpression(list.get(0), makeAndCondition(list.subList(1, list.size()))); } }
/** * 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; }
promotedCondition = term; } else { promotedCondition = new AndExpression(term, promotedCondition); retainedCondition = new AndExpression(retainedCondition, list.get(i));
promotedCondition = term; } else { promotedCondition = new AndExpression(term, promotedCondition); retainedCondition = new AndExpression(retainedCondition, list.get(i));
/** * 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 or B) => not(A) and not(B) Expression not0 = SystemFunction.makeCall("not", getRetainedStaticContext(), getLhsExpression()); Expression not1 = SystemFunction.makeCall("not", getRetainedStaticContext(), getRhsExpression()); AndExpression result = new AndExpression(not0, not1); ExpressionTool.copyLocationInfo(this, result); return result; }
/** * 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 or B) => not(A) and not(B) Expression not0 = SystemFunction.makeCall("not", getRetainedStaticContext(), getLhsExpression()); Expression not1 = SystemFunction.makeCall("not", getRetainedStaticContext(), getRhsExpression()); AndExpression result = new AndExpression(not0, not1); ExpressionTool.copyLocationInfo(this, result); return result; }
public Expression makeOptimizedFunctionCall( ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, final Expression... arguments) throws XPathException { // See if we can deduce the answer from the cardinality int c = arguments[0].getCardinality(); if (c == StaticProperty.ALLOWS_ONE_OR_MORE) { return Literal.makeLiteral(BooleanValue.FALSE, arguments[0]); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.TRUE, arguments[0]); } // Rewrite // empty(A|B) => empty(A) and empty(B) if (arguments[0] instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) arguments[0]; if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo); } } return null; }
public Expression makeOptimizedFunctionCall( ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, final Expression... arguments) throws XPathException { // See if we can deduce the answer from the cardinality int c = arguments[0].getCardinality(); if (c == StaticProperty.ALLOWS_ONE_OR_MORE) { return Literal.makeLiteral(BooleanValue.FALSE, arguments[0]); } else if (c == StaticProperty.ALLOWS_ZERO) { return Literal.makeLiteral(BooleanValue.TRUE, arguments[0]); } // Rewrite // empty(A|B) => empty(A) and empty(B) if (arguments[0] instanceof VennExpression && !visitor.isOptimizeForStreaming()) { VennExpression v = (VennExpression) arguments[0]; if (v.getOperator() == Token.UNION) { Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo); } } return null; }
return new OrExpression(lhs, rhs); case Token.AND: return new AndExpression(lhs, rhs); case Token.FEQ: case Token.FNE:
return new OrExpression(lhs, rhs); case Token.AND: return new AndExpression(lhs, rhs); case Token.FEQ: case Token.FNE:
predicate = filter; } else { predicate = new AndExpression(filter, predicate);
Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo);
Expression e0 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getLhsExpression()); Expression e1 = SystemFunction.makeCall("empty", getRetainedStaticContext(), v.getRhsExpression()); return new AndExpression(e0, e1).optimize(visitor, contextInfo);
predicate = filter; } else { predicate = new AndExpression(filter, predicate);