net.sf.saxon.sort

Class GroupByIterator

public class GroupByIterator extends 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.

Constructor Summary
GroupByIterator(SequenceIterator population, Expression keyExpression, XPathContext keyContext, Comparator collator)
Create a GroupByIterator
Method Summary
Itemcurrent()
SequenceIteratorgetAnother()
ListgetCurrentGroup()
Get the contents of the current group as a java List
AtomicValuegetCurrentGroupingKey()
Get the value of the grouping key for the current group
intgetLastPosition()
Get the last position (that is, the number of groups)
intgetProperties()
Get properties of this iterator, as a bit-significant integer.
booleanhasNext()
SequenceIteratoriterateCurrentGroup()
Get an iterator over the items in the current group
Itemnext()
intposition()

Constructor Detail

GroupByIterator

public GroupByIterator(SequenceIterator population, Expression keyExpression, XPathContext keyContext, Comparator collator)
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 Detail

current

public Item current()

getAnother

public SequenceIterator getAnother()

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

Returns: the grouping key

getLastPosition

public int getLastPosition()
Get the last position (that is, the number of groups)

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 GROUNDED, LAST_POSITION_FINDER, and 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()

iterateCurrentGroup

public SequenceIterator iterateCurrentGroup()
Get an iterator over the items in the current group

Returns: the iterator

next

public Item next()

position

public int position()