net.sf.saxon.sort

Class GroupByIterator

Implemented Interfaces:
GroupIterator, LastPositionFinder, LookaheadIterator, SequenceIterator

public class GroupByIterator
extends java.lang.Object
implements GroupIterator, LastPositionFinder, LookaheadIterator

A GroupByIterator iterates over a sequence of groups defined by xsl:for-each-group group-by="x". The groups are returned in order of first appearance. Note that an item can appear in several groups; indeed, an item may be the leading item of more than one group, which means that knowing the leading item is not enough to know the current group.

The GroupByIterator acts as a SequenceIterator, where successive calls of next() return the leading item of each group in turn. The current item of the iterator is therefore the leading item of the current group. To get access to all the members of the current group, the method iterateCurrentGroup() is used; this underpins the current-group() function in XSLT. The grouping key for the current group is available via the getCurrentGroupingKey() method.

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

GROUNDED, LAST_POSITION_FINDER, LOOKAHEAD

Constructor Summary

GroupByIterator(SequenceIterator population, Expression keyExpression, XPathContext keyContext, StringCollator collator)
Create a GroupByIterator

Method Summary

Item
current()
SequenceIterator
getAnother()
List
getCurrentGroup()
Get the contents of the current group as a java List
AtomicValue
getCurrentGroupingKey()
Get the value of the grouping key for the current group
int
getLastPosition()
Get the last position (that is, the number of groups)
int
getProperties()
Get properties of this iterator, as a bit-significant integer.
boolean
hasNext()
Determine whether there are more items to come.
SequenceIterator
iterateCurrentGroup()
Get an iterator over the items in the current group
Item
next()
int
position()

Constructor Details

GroupByIterator

public GroupByIterator(SequenceIterator population,
                       Expression keyExpression,
                       XPathContext keyContext,
                       StringCollator collator)
            throws XPathException
Create a GroupByIterator
Parameters:
population - iterator over the population to be grouped
keyExpression - the expression used to calculate the grouping key
keyContext - dynamic context for calculating the grouping key
collator - Collation to be used for comparing grouping keys
Throws:
XPathException -

Method Details

current

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

getAnother

public SequenceIterator getAnother()
            throws XPathException
Specified by:
getAnother in interface SequenceIterator

getCurrentGroup

public List getCurrentGroup()
Get the contents of the current group as a java List
Returns:
the contents of the current group

getCurrentGroupingKey

public AtomicValue getCurrentGroupingKey()
Get the value of the grouping key for the current group
Specified by:
getCurrentGroupingKey in interface GroupIterator
Returns:
the grouping key

getLastPosition

public int getLastPosition()
            throws XPathException
Get the last position (that is, the number of groups)
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.

hasNext

public boolean hasNext()
Specified by:
hasNext in interface LookaheadIterator
Returns:
true if there are more items in the sequence

iterateCurrentGroup

public SequenceIterator iterateCurrentGroup()
Get an iterator over the items in the current group
Specified by:
iterateCurrentGroup in interface GroupIterator
Returns:
the iterator

next

public Item next()
            throws XPathException
Specified by:
next in interface SequenceIterator

position

public int position()
Specified by:
position in interface SequenceIterator