Пример #1
0
 /*@NotNull*/
 public Expression optimize(
     /*@NotNull*/ ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)
     throws XPathException {
   Expression e2 = super.optimize(visitor, contextItemType);
   if (e2 != this) {
     return e2;
   }
   // See if we can deduce the answer from the cardinality
   int c = argument[0].getCardinality();
   if (c == StaticProperty.ALLOWS_ONE_OR_MORE) {
     return new Literal(BooleanValue.FALSE);
   } else if (c == StaticProperty.ALLOWS_ZERO) {
     return new Literal(BooleanValue.TRUE);
   }
   // Rewrite
   //    empty(A|B) => empty(A) and empty(B)
   if (argument[0] instanceof VennExpression) {
     VennExpression v = (VennExpression) argument[0];
     if (v.getOperator() == Token.UNION && !visitor.isOptimizeForStreaming()) {
       FunctionCall e0 =
           SystemFunction.makeSystemFunction("empty", new Expression[] {v.getOperands()[0]});
       FunctionCall e1 =
           SystemFunction.makeSystemFunction("empty", new Expression[] {v.getOperands()[1]});
       return new AndExpression(e0, e1).optimize(visitor, contextItemType);
     }
   }
   return this;
 }
Пример #2
0
 /**
  * Return the negation of the expression
  *
  * @return the negation of the expression
  */
 public Expression negate() {
   FunctionCall fc = SystemFunction.makeSystemFunction("exists", getArguments());
   fc.setLocationId(getLocationId());
   return fc;
 }