/** * Compute the static properties of this expression (other than its type). For a * Value, the only special property is {@link StaticProperty#NO_NODES_NEWLY_CREATED}. * * @return the value {@link StaticProperty#NO_NODES_NEWLY_CREATED} */ public int computeSpecialProperties() { if (value.getLength() == 0) { // An empty sequence has all special properties except "has side effects". return StaticProperty.SPECIAL_PROPERTY_MASK & ~StaticProperty.HAS_SIDE_EFFECTS; } return StaticProperty.NO_NODES_NEWLY_CREATED; }
/** * Determine whether this is a vacuous expression as defined in the XQuery update specification * * @return true if this expression is vacuous */ public boolean isVacuousExpression() { return value.getLength() == 0; }
/** * Determine whether this is a vacuous expression as defined in the XQuery update specification * * @return true if this expression is vacuous */ public boolean isVacuousExpression() { return value.getLength() == 0; }
/** * Compute the static properties of this expression (other than its type). For a * Value, the only special property is {@link StaticProperty#NO_NODES_NEWLY_CREATED}. * * @return the value {@link StaticProperty#NO_NODES_NEWLY_CREATED} */ public int computeSpecialProperties() { if (value.getLength() == 0) { // An empty sequence has all special properties except "has side effects". return StaticProperty.SPECIAL_PROPERTY_MASK & ~StaticProperty.HAS_SIDE_EFFECTS; } return StaticProperty.NO_NODES_NEWLY_CREATED; }
/** * Get the size of the value (the number of items) * * @return the number of items in the sequence */ public int getLength() { if (extent != null) { return extent.size(); } else { int n = 0; for (GroundedValue v : children) { n += v.getLength(); } return n; } }
/** * Is this expression the same as another expression? * * @throws ClassCastException if the values are not comparable */ public boolean equals(/*@NotNull*/ Object other) { if (!(other instanceof GroundedValue && ((GroundedValue)other).getLength() == 0)) { throw new ClassCastException("Cannot compare " + other.getClass() + " to empty sequence"); } return true; }
/** * Is this expression the same as another expression? * * @throws ClassCastException if the values are not comparable */ public boolean equals(/*@NotNull*/ Object other) { if (!(other instanceof GroundedValue && ((GroundedValue)other).getLength() == 0)) { throw new ClassCastException("Cannot compare " + other.getClass() + " to empty sequence"); } return true; }
/** * Test whether the literal explicitly wraps an empty sequence. (Note, if this method returns false, * this still leaves the possibility that the literal wraps a sequence that happens to be empty). * * @param exp an expression * @return true if the expression is a literal and the value of the literal is an empty sequence */ public static boolean isEmptySequence(Expression exp) { return exp instanceof Literal && ((Literal) exp).getValue().getLength() == 0; }
/** * Test whether the literal explicitly wraps an empty sequence. (Note, if this method returns false, * this still leaves the possibility that the literal wraps a sequence that happens to be empty). * * @param exp an expression * @return true if the expression is a literal and the value of the literal is an empty sequence */ public static boolean isEmptySequence(Expression exp) { return exp instanceof Literal && ((Literal) exp).getValue().getLength() == 0; }
/** * Evaluate an updating expression, adding the results to a Pending Update List. * The default implementation of this method, which is used for non-updating expressions, * throws an UnsupportedOperationException. The implementation for a literal representing * an empty sequence, however, is a no-op. * * @param context the XPath dynamic evaluation context * @param pul the pending update list to which the results should be written */ public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException { if (value.getLength() == 0) { // do nothing } else { super.evaluatePendingUpdates(context, pul); } }
/** * Produce a short string identifying the expression for use in error messages * * @return a short string, sufficient to identify the expression */ @Override public String toShortString() { if (value.getLength() == 0) { return "()"; } else if (value instanceof AtomicValue) { return value.toString(); } else { return "(" + value.head() + ",...)"; } }
public static CharSequence depictSequence(Sequence<?> seq) { try { GroundedValue<?> val = seq.materialize(); if (val.getLength() == 0) { return "()"; } else if (val.getLength() == 1) { return depict(seq.head()); } else { return depictSequenceStart(val.iterate(), 3, val.getLength()); } } catch (XPathException e) { return "(*unreadable*)"; } }
/** * Get the length of a sequence (the number of items it contains) * * @param sequence the sequence * @return the length in items * @throws XPathException if an error occurs (due to lazy evaluation) */ public static int getLength(Sequence<?> sequence) throws XPathException { if (sequence instanceof GroundedValue) { return ((GroundedValue) sequence).getLength(); } return Count.count(sequence.iterate()); }
/** * Get the length of a sequence (the number of items it contains) * * @param sequence the sequence * @return the length in items * @throws XPathException if an error occurs (due to lazy evaluation) */ public static int getLength(Sequence<?> sequence) throws XPathException { if (sequence instanceof GroundedValue) { return ((GroundedValue) sequence).getLength(); } return Count.count(sequence.iterate()); }
/** * Evaluate the expression * * @param context the dynamic evaluation context * @param arguments the values of the arguments, supplied as Sequences * @return the result of the evaluation, in the form of a Sequence * @throws net.sf.saxon.trans.XPathException * if a dynamic error occurs during the evaluation of the expression */ public IntegerValue call(XPathContext context, Sequence[] arguments) throws XPathException { Sequence<?> arg = arguments[0]; int size = arg instanceof GroundedValue ? ((GroundedValue)arg).getLength() : count(arg.iterate()); return Int64Value.makeIntegerValue(size); }
/** * Evaluate the expression * * @param context the dynamic evaluation context * @param arguments the values of the arguments, supplied as Sequences * @return the result of the evaluation, in the form of a Sequence * @throws net.sf.saxon.trans.XPathException * if a dynamic error occurs during the evaluation of the expression */ public IntegerValue call(XPathContext context, Sequence[] arguments) throws XPathException { Sequence<?> arg = arguments[0]; int size = arg instanceof GroundedValue ? ((GroundedValue)arg).getLength() : count(arg.iterate()); return Int64Value.makeIntegerValue(size); }
private void writeSequence(GroundedValue<?> seq) throws XPathException { int len = seq.getLength(); if (len == 0) { emitter.writeAtomicValue(null); } else if (len == 1) { level++; write(seq.head()); level--; } else { throw new XPathException("JSON serialization: cannot handle a sequence of length " + len + Err.depictSequence(seq), "SERE0023"); } }
private void writeSequence(GroundedValue<?> seq) throws XPathException { int len = seq.getLength(); if (len == 0) { emitter.writeAtomicValue(null); } else if (len == 1) { level++; write(seq.head()); level--; } else { throw new XPathException("JSON serialization: cannot handle a sequence of length " + len + Err.depictSequence(seq), "SERE0023"); } }
protected Expression preEvaluate() throws XPathException { GroundedValue literalOperand = ((Literal) getBaseExpression()).getValue(); if (literalOperand instanceof AtomicValue && converter != null) { ConversionResult result = converter.convert((AtomicValue) literalOperand); return Literal.makeLiteral(BooleanValue.get(!(result instanceof ValidationFailure)), this); } final int length = literalOperand.getLength(); if (length == 0) { return Literal.makeLiteral(BooleanValue.get(allowsEmpty()), this); } if (length > 1) { return Literal.makeLiteral(BooleanValue.FALSE, this); } return this; }
protected Expression preEvaluate() throws XPathException { GroundedValue literalOperand = ((Literal) getBaseExpression()).getValue(); if (literalOperand instanceof AtomicValue && converter != null) { ConversionResult result = converter.convert((AtomicValue) literalOperand); return Literal.makeLiteral(BooleanValue.get(!(result instanceof ValidationFailure)), this); } final int length = literalOperand.getLength(); if (length == 0) { return Literal.makeLiteral(BooleanValue.get(allowsEmpty()), this); } if (length > 1) { return Literal.makeLiteral(BooleanValue.FALSE, this); } return this; }