net.sf.saxon.functions

Class Aggregate

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

public class Aggregate
extends SystemFunction

This class implements the sum(), avg(), count() functions,

Field Summary

static int
AVG
static int
COUNT
static int
SUM

Fields inherited from class net.sf.saxon.functions.SystemFunction

operation

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

argument

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

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Method Summary

static AtomicValue
average(SequenceIterator iter, XPathContext context, SourceLocator location)
Calculate average
void
checkArguments(ExpressionVisitor visitor)
Static analysis: prevent sorting of the argument
int
computeCardinality()
Determine the cardinality of the function.
static int
count(SequenceIterator iter)
Get the number of items in a sequence identified by a SequenceIterator
Item
evaluateItem(XPathContext context)
Evaluate the function
ItemType
getItemType(TypeHierarchy th)
Determine the item type of the value returned by the function
static boolean
isCountFunction(Expression exp)
Determine whether a given expression is a call to the count() function
static AtomicValue
total(SequenceIterator iter, XPathContext context, SourceLocator location)
Calculate the total of a sequence.

Methods inherited from class net.sf.saxon.functions.SystemFunction

addContextDocumentArgument, addDocToPathMap, checkArguments, computeCardinality, computeSpecialProperties, copy, getDetails, getErrorCodeForTypeErrors, getItemType, getRequiredType, makeSystemFunction, optimize, setDetails, useContextItemAsDefault

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

addExternalFunctionCallToPathMap, checkArgumentCount, checkArguments, equals, explain, getArguments, getDisplayName, getFunctionName, getNumberOfArguments, hashCode, iterateSubExpressions, optimize, preEvaluate, promote, replaceSubExpression, setArguments, setFunctionName, simplify, simplifyArguments, toString, typeCheck

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

Field Details

AVG

public static final int AVG
Field Value:
1

COUNT

public static final int COUNT
Field Value:
4

SUM

public static final int SUM
Field Value:
0

Method Details

average

public static AtomicValue average(SequenceIterator iter,
                                  XPathContext context,
                                  SourceLocator location)
            throws XPathException
Calculate average
Parameters:
iter - iterator over the items to be totalled
context - the XPath dynamic context
location - location of the expression in the source for diagnostics
Returns:
the average of the values

checkArguments

public void checkArguments(ExpressionVisitor visitor)
            throws XPathException
Static analysis: prevent sorting of the argument
Overrides:
checkArguments in interface SystemFunction

computeCardinality

public int computeCardinality()
Determine the cardinality of the function.
Overrides:
computeCardinality in interface SystemFunction

count

public static int count(SequenceIterator iter)
            throws XPathException
Get the number of items in a sequence identified by a SequenceIterator
Parameters:
iter - The SequenceIterator. This method moves the current position of the supplied iterator; if this isn't safe, make a copy of the iterator first by calling getAnother(). The supplied iterator must be positioned before the first item (there must have been no call on next()).
Returns:
the number of items in the underlying sequence
Throws:
XPathException - if a failure occurs reading the input sequence

evaluateItem

public Item evaluateItem(XPathContext context)
            throws XPathException
Evaluate the function
Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in interface Expression

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the item type of the value returned by the function
Overrides:
getItemType in interface SystemFunction
Parameters:
th - the type hierarchy cache

isCountFunction

public static boolean isCountFunction(Expression exp)
Determine whether a given expression is a call to the count() function
Parameters:
exp - an expression to be examined
Returns:
true if the expression is a call to the count() function

total

public static AtomicValue total(SequenceIterator iter,
                                XPathContext context,
                                SourceLocator location)
            throws XPathException
Calculate the total of a sequence.
Parameters:
iter - iterator over the items to be totalled
context - the XPath dynamic context
location - location of the expression in the source for diagnostics
Returns:
the total, according to the rules of the XPath sum() function, but returning null if the sequence is empty. (It's then up to the caller to decide what the correct result is for an empty sequence.