Package net.sf.saxon.om
Class MemoSequence<T extends Item<?>>
- java.lang.Object
-
- net.sf.saxon.om.MemoSequence<T>
-
- All Implemented Interfaces:
Sequence<T>
public class MemoSequence<T extends Item<?>> extends Object implements Sequence<T>
A Sequence implementation that represents a lazy evaluation of a supplied iterator. Items are read from the base iterator only when they are first required, and are then remembered within the local storage of the MemoSequence, which eventually (if the sequence is read to the end) contains the entire value.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMemoSequence.ProgressiveIteratorA ProgressiveIterator starts by reading any items already held in the reservoir; when the reservoir is exhausted, it reads further items from the inputIterator, copying them into the reservoir as they are read.
-
Field Summary
Fields Modifier and Type Field Description protected static intEMPTY(package private) SequenceIterator<T>inputIteratorprotected intstate
-
Constructor Summary
Constructors Constructor Description MemoSequence(SequenceIterator<T> iterator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Thead()Get the first item in the sequence.ItemitemAt(int n)Get the Nth item in the sequence (0-based), reading new items into the internal reservoir if necessarySequenceIterator<T>iterate()Get aSequenceIteratorover all the items in the sequence-
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
asIterable, makeRepeatable, materialize
-
-
-
-
Field Detail
-
inputIterator
SequenceIterator<T extends Item<?>> inputIterator
-
state
protected int state
-
EMPTY
protected static final int EMPTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MemoSequence
public MemoSequence(SequenceIterator<T> iterator)
-
-
Method Detail
-
head
public T head() throws XPathException
Description copied from interface:SequenceGet the first item in the sequence.- Specified by:
headin interfaceSequence<T extends Item<?>>- Returns:
- the first item in the sequence if there is one, or null if the sequence is empty
- Throws:
XPathException- in the situation where the sequence is evaluated lazily, and evaluation of the first item causes a dynamic error.
-
iterate
public SequenceIterator<T> iterate() throws XPathException
Description copied from interface:SequenceGet aSequenceIteratorover all the items in the sequence- Specified by:
iteratein interfaceSequence<T extends Item<?>>- Returns:
- an iterator (specifically, a Saxon
SequenceIterator, which is not aIterator) over all the items - Throws:
XPathException- in the situation where the sequence is evaluated lazily, and constructing an iterator over the items causes a dynamic error.
-
itemAt
public Item itemAt(int n) throws XPathException
Get the Nth item in the sequence (0-based), reading new items into the internal reservoir if necessary- Parameters:
n- the index of the required item- Returns:
- the Nth item if it exists, or null otherwise
- Throws:
XPathException- if the input sequence cannot be read
-
-