net.sf.saxon.sort

Class TupleSorter

public class TupleSorter extends Expression

A TupleSorter is an expression that sorts a stream of tuples. It is used to implement XQuery FLWR expressions.
Nested Class Summary
static classTupleSorter.TupleUnwrapper
Mapping function to map the wrapped objects returned by the SortedTupleIterator into real items.
Constructor Summary
TupleSorter(Expression base, SortKeyDefinition[] keys)
Create a TupleSorter
Method Summary
intcomputeCardinality()
Expressioncopy()
Copy an expression.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
ExpressiongetBaseExpression()
Get the base expression, the expression that computes the sequence to be sorted
AtomicComparer[]getComparators()
Get the array of AtomicComparer objects, one per sort key, that are used to compare values in the sequence
ItemTypegetItemType(TypeHierarchy th)
SequenceIteratoriterate(XPathContext context)
Iterator<Expression>iterateSubExpressions()
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
Expressionpromote(PromotionOffer offer, Expression parent)
Promote this expression if possible
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
Expressionsimplify(ExpressionVisitor visitor)
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Constructor Detail

TupleSorter

public TupleSorter(Expression base, SortKeyDefinition[] keys)
Create a TupleSorter

Parameters: base The base expression returns the sequence of tuples to be sorted. Each tuple is represented by an ObjectValue which wraps a Value (that is, in general, a sequence) keys Although this class uses the SortKeyDefinition class to define the sort keys, the actual sort key expression in the SortKeyDefinition is not used. This is because the sort key is instead computed as one of the members of the tuple delivered by the TupleSorter. Therefore, the sort key expression is not managed as a child of this expression. Moreover, in xquery the other aspects of a sort key are always fixed statically, so we don't treat those as subexpressions either.

Method Detail

computeCardinality

public int computeCardinality()

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

getBaseExpression

public Expression getBaseExpression()
Get the base expression, the expression that computes the sequence to be sorted

Returns: the base expression

getComparators

public AtomicComparer[] getComparators()
Get the array of AtomicComparer objects, one per sort key, that are used to compare values in the sequence

Returns: an array of AtomicComparer objects, one per sort key

getItemType

public ItemType getItemType(TypeHierarchy th)

iterate

public SequenceIterator iterate(XPathContext context)

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

promote

public Expression promote(PromotionOffer offer, Expression parent)
Promote this expression if possible

replaceSubExpression

public boolean replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression

Parameters: original the original subexpression replacement the replacement subexpression

Returns: true if the original subexpression is found

simplify

public Expression simplify(ExpressionVisitor visitor)

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)