net.sf.saxon.sort

Class SortedIterator

public class SortedIterator extends Object implements SequenceIterator, LastPositionFinder, LookaheadIterator, Sortable

Class to do a sorted iteration
Field Summary
protected SequenceIteratorbase
protected AtomicComparer[]comparators
protected XPathContextcontext
protected intcount
protected Object[]nodeKeys
protected intposition
protected intrecordSize
protected SortKeyEvaluatorsortKeyEvaluator
Constructor Summary
SortedIterator(XPathContext context, SequenceIterator base, SortKeyEvaluator sortKeyEvaluator, AtomicComparer[] comparators)
Create a sorted iterator
Method Summary
protected voidbuildArray()
Create an array holding the items to be sorted and the values of their sort keys
voidclose()
intcompare(int a, int b)
Compare two items in sorted sequence (needed to implement the Sortable interface)
Itemcurrent()
SequenceIteratorgetAnother()
intgetLastPosition()
intgetProperties()
Get properties of this iterator, as a bit-significant integer.
booleanhasNext()
Determine whether there are more items to come.
Itemnext()
Get the next item, in sorted order
intposition()
voidsetHostLanguage(int language)
Set the host language
voidswap(int a, int b)
Swap two items (needed to implement the Sortable interface)

Field Detail

base

protected SequenceIterator base

comparators

protected AtomicComparer[] comparators

context

protected XPathContext context

count

protected int count

nodeKeys

protected Object[] nodeKeys

position

protected int position

recordSize

protected int recordSize

sortKeyEvaluator

protected SortKeyEvaluator sortKeyEvaluator

Constructor Detail

SortedIterator

public SortedIterator(XPathContext context, SequenceIterator base, SortKeyEvaluator sortKeyEvaluator, AtomicComparer[] comparators)
Create a sorted iterator

Parameters: context the dynamic XPath evaluation context base an iterator over the sequence to be sorted sortKeyEvaluator an object that allows the n'th sort key for a given item to be evaluated comparators an array of AtomicComparers, one for each sort key, for comparing sort key values

Method Detail

buildArray

protected void buildArray()
Create an array holding the items to be sorted and the values of their sort keys

Throws: XPathException

close

public void close()

compare

public int compare(int a, int b)
Compare two items in sorted sequence (needed to implement the Sortable interface)

Returns: <0 if obj[a]0 if obj[a]>obj[b]

current

public Item current()

getAnother

public SequenceIterator getAnother()

getLastPosition

public int getLastPosition()

getProperties

public int getProperties()
Get properties of this iterator, as a bit-significant integer.

Returns: the properties of this iterator. This will be some combination of properties such as SortedIterator, SortedIterator, and SortedIterator. 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.

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.

This method must not be called unless the result of getProperties() on the iterator includes the bit setting LOOKAHEAD

Returns: true if there are more items in the sequence

next

public Item next()
Get the next item, in sorted order

position

public int position()

setHostLanguage

public void setHostLanguage(int language)
Set the host language

Parameters: language the host language (for example XQUERY)

swap

public void swap(int a, int b)
Swap two items (needed to implement the Sortable interface)