net.sf.saxon.sort
Class SortedIterator

java.lang.Object
  extended bynet.sf.saxon.sort.SortedIterator
All Implemented Interfaces:
LastPositionFinder, SequenceIterator, Sortable
Direct Known Subclasses:
SortedGroupIterator, SortedTupleIterator

public class SortedIterator
extends Object
implements SequenceIterator, LastPositionFinder, Sortable

Class to do a sorted iteration


Field Summary
protected  SequenceIterator base
           
protected  XPathContext context
           
protected  int count
           
protected  int index
           
protected  Object[] nodeKeys
           
protected  int recordSize
           
protected  FixedSortKeyDefinition[] sortkeys
           
 
Constructor Summary
SortedIterator(XPathContext context, SequenceIterator base, FixedSortKeyDefinition[] sortkeys)
           
 
Method Summary
protected  void buildArray()
           
 int compare(int a, int b)
          Compare two items in sorted sequence (needed to implement the Sortable interface)
 Item current()
          Get the current value in the sequence (the one returned by the most recent call on next()).
 SequenceIterator getAnother()
          Get another SequenceIterator that iterates over the same items as the original, but which is repositioned at the start of the sequence.
 int getLastPosition()
          Get the last position (that is, the number of items in the sequence)
 Item next()
          Get the next item, in sorted order
 int position()
          Get the current position.
 void swap(int a, int b)
          Swap two items (needed to implement the Sortable interface)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

protected SequenceIterator base

sortkeys

protected FixedSortKeyDefinition[] sortkeys

recordSize

protected int recordSize

nodeKeys

protected Object[] nodeKeys

count

protected int count

index

protected int index

context

protected XPathContext context
Constructor Detail

SortedIterator

public SortedIterator(XPathContext context,
                      SequenceIterator base,
                      FixedSortKeyDefinition[] sortkeys)
               throws XPathException
Method Detail

next

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

Specified by:
next in interface SequenceIterator
Returns:
the next item, or null if there are no more items.
Throws:
XPathException - if an error occurs retrieving the next item

current

public Item current()
Description copied from interface: SequenceIterator
Get the current value in the sequence (the one returned by the most recent call on next()). This will be null before the first call of next().

Specified by:
current in interface SequenceIterator
Returns:
the current item, the one most recently returned by a call on next(); or null, if next() has not been called, or if the end of the sequence has been reached.

position

public int position()
Description copied from interface: SequenceIterator
Get the current position. This will be zero before the first call on next(), otherwise it will be the number of times that next() has been called.

Specified by:
position in interface SequenceIterator
Returns:
the current position, the position of the item returned by the most recent call of next()

getLastPosition

public int getLastPosition()
                    throws XPathException
Description copied from interface: LastPositionFinder
Get the last position (that is, the number of items in the sequence)

Specified by:
getLastPosition in interface LastPositionFinder
Throws:
XPathException

getAnother

public SequenceIterator getAnother()
                            throws XPathException
Description copied from interface: SequenceIterator
Get another SequenceIterator that iterates over the same items as the original, but which is repositioned at the start of the sequence.

Specified by:
getAnother in interface SequenceIterator
Returns:
a SequenceIterator that iterates over the same items, positioned before the first item
Throws:
XPathException - if any error occurs

buildArray

protected void buildArray()
                   throws XPathException
Throws:
XPathException

compare

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

Specified by:
compare in interface Sortable
Returns:
<0 if obj[a]0 if obj[a]>obj[b]

swap

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

Specified by:
swap in interface Sortable