public class FocusTrackingIterator extends java.lang.Object implements FocusIterator, LookaheadIterator, GroundedIterator, LastPositionFinder
Note that when a FocusTrackingIterator is used to wrap a SequenceIterator in order to track the values of position() and current(), it is important to ensure (a) that the SequenceIterator is initially positioned at the start of the sequence, and (b) that all calls on next() to advance the iterator are directed at the FocusTrackingIterator, and not at the wrapped SequenceIterator.
Constructor and Description |
---|
FocusTrackingIterator(SequenceIterator base) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the iterator.
|
Item |
current()
Get the current value in the sequence (the one returned by the
most recent call on next()).
|
void |
discharge()
Calling this method instructs the iterator to release any resources it holds, while still
remaining able to deliver the remaining items in the sequence.
|
int |
getLength()
Get the position of the last item in the sequence.
|
GroundedValue |
getResidue()
Return a GroundedValue containing all the remaining items in the sequence returned by this
SequenceIterator, starting at the current position.
|
int |
getSiblingPosition(NodeInfo node,
NodeTest nodeTest,
int max)
Get the sibling position of a node: specifically, count how many preceding siblings
of a node satisfy the nodetest.
|
SequenceIterator |
getUnderlyingIterator()
Get the underlying iterator
|
boolean |
hasNext()
Determine whether there are more items to come.
|
boolean |
isActuallyGrounded()
Ask if the iterator is actually grounded.
|
GroundedValue |
materialize()
Return a GroundedValue containing all the items in the sequence returned by this
SequenceIterator.
|
Item |
next()
Get the next item in the sequence.
|
int |
position()
Get the current position.
|
boolean |
supportsGetLength()
Ask whether this iterator supports use of the
getLength() method. |
boolean |
supportsHasNext()
Ask whether the hasNext() method can be called.
|
static FocusTrackingIterator |
track(SequenceIterator base) |
public FocusTrackingIterator(SequenceIterator base)
public static FocusTrackingIterator track(SequenceIterator base)
public SequenceIterator getUnderlyingIterator()
public Item next()
next
in interface SequenceIterator
public Item current()
current
in interface FocusIterator
public int position()
This method does not change the state of the iterator.
position
in interface FocusIterator
public int getLength()
getLength
in interface LastPositionFinder
getLength
in interface FocusIterator
UncheckedXPathException
- if a failure occurs reading the sequencepublic boolean supportsGetLength()
getLength()
method. This
method should always be called before calling getLength()
, because an iterator
that implements this interface may support use of getLength()
in some situations
and not in otherssupportsGetLength
in interface LastPositionFinder
getLength()
method can be called to determine the length
of the underlying sequence.public boolean supportsHasNext()
LookaheadIterator
supportsHasNext
in interface LookaheadIterator
LookaheadIterator.hasNext()
method is availablepublic boolean hasNext()
This method must not be called unless the method supportsHasNext()
returns true.
hasNext
in interface LookaheadIterator
java.lang.ClassCastException
- if the base iterator does not support lookahead processingpublic GroundedValue materialize()
materialize
in interface GroundedIterator
UncheckedXPathException
- in the cases of subclasses (such as the iterator over a MemoClosure)
which cause evaluation of expressions while materializing the value.public GroundedValue getResidue()
getResidue
in interface GroundedIterator
UncheckedXPathException
- in the cases of subclasses (such as the iterator over a MemoClosure)
which cause evaluation of expressions while materializing the value.public void close()
(Currently, closing an iterator is important only when the data is being "pushed" in another thread. Closing the iterator terminates that thread and means that it needs to do no additional work. Indeed, failing to close the iterator may cause the push thread to hang waiting for the buffer to be emptied.)
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface SequenceIterator
public void discharge()
SequenceIterator
SequenceIterator.close()
will be called when no more items are needed.discharge
in interface SequenceIterator
public boolean isActuallyGrounded()
GroundedIterator
GroundedIterator.materialize()
or GroundedIterator.getResidue()
, because the iterator might
be grounded under some conditions and not others (usually when it delegates
to another iterator)isActuallyGrounded
in interface GroundedIterator
public int getSiblingPosition(NodeInfo node, NodeTest nodeTest, int max)
xsl:apply-templates
select="*"
(which selects a set of sibling nodes) is used in conjunction with patterns
such as match="*[position() mod 2 = 1]
, then calculation of the position of one
node in the sequence of siblings can take advantage of the fact that the position of the
immediately preceding sibling is already known.
This optimization was suggested by the late Sebastian Rahtz, one of Saxon's earliest power users, and it is dedicated to his memory.
node
- the starting node, which is assumed to satisfy the node testnodeTest
- the node testmax
- the maximum number of nodes to be countedCopyright (c) 2004-2022 Saxonica Limited. All rights reserved.