/** * Produce a GroundedValue containing the same values as a supplied sequence. * * @param iterator the supplied sequence. The iterator may or may not be consumed as a result of * passing it to this method. * @return a GroundedValue containing the same items * @throws XPathException if a failure occurs reading the input iterator */ public static <T extends Item<?>> GroundedValue<T> toGroundedValue(SequenceIterator<T> iterator) throws XPathException { return iterator.materialize(); }
/** * Return a GroundedValue containing all the items in the sequence returned by this * SequenceIterator. This should be an "in-memory" value, not a Closure. * * @return the corresponding Value * @throws XPathException in the cases of subclasses (such as the iterator over a MemoClosure) * which cause evaluation of expressions while materializing the value. * @throws ClassCastException if the iterator does not have the {@link #GROUNDED} property. */ @Override public GroundedValue<T> materialize() throws XPathException { return base.materialize(); }
/** * Reduce a value to its simplest form. If the value is a closure or some other form of deferred value * such as a FunctionCallPackage, then it is reduced to a SequenceExtent. If it is a SequenceExtent containing * a single item, then it is reduced to that item. One consequence that is exploited by class FilterExpression * is that if the value is a singleton numeric value, then the result will be an instance of NumericValue * @return the simplified value * @throws XPathException if an error occurs doing the lazy evaluation */ public GroundedValue<?> reduce() throws XPathException { return iterate().materialize(); }
/** * Make a SequenceExtent, given the expected reference count * * @param expression the expression to be evaluated * @param ref the (nominal) number of times the value of the expression is required * @param context the XPath dynamic evaluation context * @return the constructed SequenceExtent * @throws XPathException if evaluation of the expression fails */ public GroundedValue<?> makeSequenceExtent(Expression expression, int ref, XPathContext context) throws XPathException { return expression.iterate(context).materialize(); }
@Override public Sequence<?> evaluate(Expression expr, XPathContext context) throws XPathException { SequenceIterator<?> iter = expr.iterate(context); return iter.materialize(); }
public Sequence<?> convert(Object object, XPathContext context) throws XPathException { return object instanceof Closure ? ((Closure) object).iterate().materialize() : (Sequence<?>) object; }
/** * Create a {@link GroundedValue} containing the same items as this Sequence. * A {@code GroundedValue} typically contains the entire sequence in memory; at * any rate, it guarantees that the entire sequence can be read without any * possibility of XPath dynamic errors arising. * @return a {@link GroundedValue} containing the same items as this Sequence * @throws XPathException if evaluating the contents of the sequence fails with * a dynamic error. */ default GroundedValue<T> materialize() throws XPathException { return iterate().materialize(); }
public Sequence<?> convert(Object object, XPathContext context) throws XPathException { return object instanceof Closure ? ((Closure) object).iterate().materialize() : (Sequence<?>) object; }
@Override public Sequence<?> evaluate(Expression expr, XPathContext context) throws XPathException { SequenceIterator<?> iter = expr.iterate(context); return iter.materialize(); }
/** * Make a SequenceExtent, given the expected reference count * * @param expression the expression to be evaluated * @param ref the (nominal) number of times the value of the expression is required * @param context the XPath dynamic evaluation context * @return the constructed SequenceExtent * @throws XPathException if evaluation of the expression fails */ public GroundedValue<?> makeSequenceExtent(Expression expression, int ref, XPathContext context) throws XPathException { return expression.iterate(context).materialize(); }
/** * Create a {@link GroundedValue} containing the same items as this Sequence. * A {@code GroundedValue} typically contains the entire sequence in memory; at * any rate, it guarantees that the entire sequence can be read without any * possibility of XPath dynamic errors arising. * @return a {@link GroundedValue} containing the same items as this Sequence * @throws XPathException if evaluating the contents of the sequence fails with * a dynamic error. */ default GroundedValue<T> materialize() throws XPathException { return iterate().materialize(); }
public Object convert(Sequence<?> value, Class<?> targetClass, XPathContext context) throws XPathException { return value.iterate().materialize(); }
public static Sequence<?> toLazySequence2(SequenceIterator<?> iterator) throws XPathException { if ((iterator.getProperties() & SequenceIterator.GROUNDED) != 0 && !(iterator instanceof RangeIterator) && !(iterator instanceof ReverseRangeIterator)) { return iterator.materialize(); } else { return new LazySequence<>(iterator); } }
private static GroundedValue<? extends AtomicValue> atomize(Sequence<?> input) throws XPathException { SequenceIterator<?> iterator = input.iterate(); SequenceIterator<? extends AtomicValue> mapper = Atomizer.getAtomizingIterator(iterator, false); return mapper.materialize(); } }
/** * Get the contents of this value in the form of a Java {@link java.lang.Iterable}, * so that it can be used in a for-each expression. In the general case, obtaining * the iterable may raise dynamic errors; but the {@link java.util.Iterator} obtained * from the iterable will be error-free. Subclasses of {@link Sequence} that * implement {@link GroundedValue} are directly iterable, so this method is a no-op * in those cases. * * @return an Iterable containing the same sequence of items */ default Iterable<T> asIterable() throws XPathException { return iterate().materialize().asIterable(); }
private static GroundedValue<? extends AtomicValue> atomize(Sequence<?> input) throws XPathException { SequenceIterator<?> iterator = input.iterate(); SequenceIterator<? extends AtomicValue> mapper = Atomizer.getAtomizingIterator(iterator, false); return mapper.materialize(); } }
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { AtomicValue key = (AtomicValue) arguments[0].head(); assert key != null; GroundedValue<?> value = ((Sequence<?>)arguments[1]).iterate().materialize(); return new SingleEntryMap(key, value); }
protected static void checkGroupingValues(Sequence[] groupingValues) throws XPathException { for (int i = 0; i < groupingValues.length; i++) { Sequence<?> v = groupingValues[i]; if (!(v instanceof EmptySequence || v instanceof AtomicValue)) { v = Atomizer.getAtomizingIterator(v.iterate(), false).materialize(); if (SequenceTool.getLength(v) > 1) { throw new XPathException("Grouping key value cannot be a sequence of more than one item", "XPTY0004"); } groupingValues[i] = v; } } }
protected static void checkGroupingValues(Sequence[] groupingValues) throws XPathException { for (int i = 0; i < groupingValues.length; i++) { Sequence<?> v = groupingValues[i]; if (!(v instanceof EmptySequence || v instanceof AtomicValue)) { v = Atomizer.getAtomizingIterator(v.iterate(), false).materialize(); if (SequenceTool.getLength(v) > 1) { throw new XPathException("Grouping key value cannot be a sequence of more than one item", "XPTY0004"); } groupingValues[i] = v; } } }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { getOperand().optimize(visitor, contextInfo); if (getBaseExpression() instanceof Literal) { GroundedValue<?> value = iterate(visitor.getStaticContext().makeEarlyEvaluationContext()).materialize(); return Literal.makeLiteral(value, this); } return this; }