net.sf.saxon.sort

Class TupleSorter

Implemented Interfaces:
EvaluableItem, InstructionInfoProvider, SequenceIterable, Serializable, SourceLocator

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 class
TupleSorter.TupleUnwrapper
Mapping function to map the wrapped objects returned by the SortedTupleIterator into real items.

Field Summary

Fields inherited from class net.sf.saxon.expr.Expression

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

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

Method Summary

int
computeCardinality()
Expression
copy()
Copy an expression.
void
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
Expression
getBaseExpression()
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
ItemType
getItemType(TypeHierarchy th)
SequenceIterator
iterate(XPathContext context)
Iterator
iterateSubExpressions()
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
Expression
promote(PromotionOffer offer)
Promote this expression if possible
boolean
replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
Expression
simplify(ExpressionVisitor visitor)
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Methods inherited from class net.sf.saxon.expr.Expression

addToPathMap, adoptChildExpression, checkPermittedContents, computeCardinality, computeDependencies, computeSpecialProperties, computeStaticProperties, copy, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, explain, findParentOf, getCardinality, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getItemType, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, iterateSubExpressions, markTailFunctionCalls, optimize, process, promote, replaceSubExpression, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, toString, typeCheck, typeError

Constructor Details

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 Details

computeCardinality

public int computeCardinality()
Overrides:
computeCardinality in interface Expression

copy

public Expression copy()
Copy an expression. This makes a deep copy.
Overrides:
copy in interface Expression
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.
Overrides:
explain in interface Expression

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)
Overrides:
getItemType in interface Expression

iterate

public SequenceIterator iterate(XPathContext context)
            throws XPathException
Specified by:
iterate in interface SequenceIterable
Overrides:
iterate in interface Expression

iterateSubExpressions

public Iterator iterateSubExpressions()
Overrides:
iterateSubExpressions in interface Expression

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
            throws XPathException
Overrides:
optimize in interface Expression

promote

public Expression promote(PromotionOffer offer)
            throws XPathException
Promote this expression if possible
Overrides:
promote in interface Expression

replaceSubExpression

public boolean replaceSubExpression(Expression original,
                                    Expression replacement)
Replace one subexpression by a replacement subexpression
Overrides:
replaceSubExpression in interface Expression
Parameters:
original - the original subexpression
replacement - the replacement subexpression
Returns:
true if the original subexpression is found

simplify

public Expression simplify(ExpressionVisitor visitor)
            throws XPathException
Overrides:
simplify in interface Expression

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
Overrides:
typeCheck in interface Expression