Package net.sf.saxon.om
Class LazySequence
java.lang.Object
net.sf.saxon.om.LazySequence
- All Implemented Interfaces:
Sequence
A sequence that wraps an iterator, without being materialized. It can only be used once.
-
Constructor Summary
ConstructorsConstructorDescriptionLazySequence
(SequenceIterator iterator) Create a virtual sequence backed by an iterator -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.sf.saxon.om.Sequence
materialize
-
Constructor Details
-
LazySequence
Create a virtual sequence backed by an iterator- Parameters:
iterator
- the iterator that delivers the items in the sequence
-
-
Method Details
-
head
Get the first item in the sequence. This calls iterate() internally, which means it can only be called once; the method should only be used if the client requires only the first item in the sequence (or knows that the sequence has length one).- Specified by:
head
in interfaceSequence
- Returns:
- the first item, or null if the sequence is empty
- Throws:
XPathException
- if an error occurs evaluating the underlying expression
-
iterate
Iterate over all the items in the sequence. The first time this is called it returns the original iterator backing the sequence. On subsequent calls it clones the original iterator.- Specified by:
iterate
in interfaceSequence
- Returns:
- an iterator over the items in the sequence
- Throws:
UncheckedXPathException
- if evaluation of the iterator fails.IllegalStateException
- if iterate() has already been called
-
makeRepeatable
Description copied from interface:Sequence
Ensure that the sequence is in a form where it can be evaluated more than once. Some sequences (for exampleLazySequence
andClosure
can only be evaluated once, and this operation causes these to be grounded. However, making it repeatable is not the same as making it grounded; it does not flush out all errors. Indeed, lazy evaluation relies on this property, because an expression that has been lifted out of a loop must not be evaluated unless the loop is executed at least once, to prevent spurious errors.- Specified by:
makeRepeatable
in interfaceSequence
- Returns:
- An equivalent sequence that can be repeatedly evaluated
- Throws:
XPathException
- if evaluation fails
-