net.sf.saxon.om

Class SingletonIterator

Implemented Interfaces:
GroundedIterator, LastPositionFinder, LookaheadIterator, ReversibleIterator, SequenceIterator, UnfailingIterator

public class SingletonIterator
extends java.lang.Object
implements UnfailingIterator, ReversibleIterator, LastPositionFinder, GroundedIterator, LookaheadIterator

SingletonIterator: an iterator over a sequence of zero or one values

Fields inherited from interface net.sf.saxon.om.SequenceIterator

GROUNDED, LAST_POSITION_FINDER, LOOKAHEAD

Method Summary

Item
current()
SequenceIterator
getAnother()
int
getLastPosition()
Get the last position (that is, the number of items in the sequence).
int
getProperties()
Get properties of this iterator, as a bit-significant integer.
SequenceIterator
getReverseIterator()
Item
getValue()
boolean
hasNext()
Determine whether there are more items to come.
static UnfailingIterator
makeIterator(Item item)
Factory method.
GroundedValue
materialize()
Return a Value containing all the items in the sequence returned by this SequenceIterator
Item
next()
int
position()
Return the current position in the sequence.

Method Details

current

public Item current()
Specified by:
current in interface UnfailingIterator
current in interface SequenceIterator

getAnother

public SequenceIterator getAnother()
Specified by:
getAnother in interface UnfailingIterator
getAnother in interface SequenceIterator

getLastPosition

public int getLastPosition()
Specified by:
getLastPosition in interface LastPositionFinder

getProperties

public int getProperties()
Get properties of this iterator, as a bit-significant integer.
Specified by:
getProperties in interface SequenceIterator
Returns:
the properties of this iterator. This will be some combination of properties such as SequenceIterator.GROUNDED, SequenceIterator.LAST_POSITION_FINDER, and SequenceIterator.LOOKAHEAD. It is always acceptable to return the value zero, indicating that there are no known special properties. It is acceptable for the properties of the iterator to change depending on its state.

getReverseIterator

public SequenceIterator getReverseIterator()
Specified by:
getReverseIterator in interface ReversibleIterator

getValue

public Item getValue()

hasNext

public boolean hasNext()
Determine whether there are more items to come. Note that this operation is stateless and it is not necessary (or usual) to call it before calling next(). It is used only when there is an explicit need to tell if we are at the last element.
Specified by:
hasNext in interface LookaheadIterator
Returns:
true if there are more items

makeIterator

public static UnfailingIterator makeIterator(Item item)
Factory method.
Parameters:
item - the item to iterate over
Returns:
a SingletonIterator over the supplied item, or an EmptyIterator if the supplied item is null.

materialize

public GroundedValue materialize()
Return a Value containing all the items in the sequence returned by this SequenceIterator
Specified by:
materialize in interface GroundedIterator
Returns:
the corresponding Value. If the value is a closure or a function call package, it will be evaluated and expanded.

next

public Item next()
Specified by:
next in interface UnfailingIterator
next in interface SequenceIterator

position

public int position()
Return the current position in the sequence.
Specified by:
position in interface UnfailingIterator
position in interface SequenceIterator
Returns:
0 before the first call on next(); 1 before the second call on next(); -1 after the second call on next().