Package net.sf.saxon.functions
Class Aggregate
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.FunctionCall
net.sf.saxon.functions.SystemFunction
net.sf.saxon.functions.Aggregate
- All Implemented Interfaces:
Serializable
,SourceLocator
,LocationProvider
,SaxonLocator
,EvaluableItem
,SequenceIterable
,InstructionInfo
,Locator
This class implements the sum(), avg(), count() functions,
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
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, locationId, PROCESS_METHOD, staticProperties
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AtomicValue
average
(SequenceIterator iter, XPathContext context, SourceLocator location) Calculate averagevoid
checkArguments
(ExpressionVisitor visitor) Static analysis: prevent sorting of the argumentint
Determine the cardinality of the function.static int
count
(SequenceIterator iter) Get the number of items in a sequence identified by a SequenceIteratorevaluateItem
(XPathContext context) Evaluate the functionDetermine the item type of the value returned by the functionstatic boolean
Determine whether a given expression is a call to the count() functionstatic 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, computeSpecialProperties, copy, getDetails, getErrorCodeForTypeErrors, getRequiredType, makeSystemFunction, optimize, setDetails, useContextItemAsDefault
Methods inherited from class net.sf.saxon.expr.FunctionCall
addExternalFunctionCallToPathMap, checkArgumentCount, equals, explain, getArguments, getDisplayName, getFunctionName, getNumberOfArguments, hashCode, iterateSubExpressions, preEvaluate, promote, replaceSubExpression, setArguments, setFunctionName, simplify, simplifyArguments, toString, typeCheck
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluatePendingUpdates, explain, findParentOf, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, isUpdatingExpression, iterate, iterateEvents, markTailFunctionCalls, process, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, typeError
-
Field Details
-
SUM
public static final int SUM- See Also:
-
AVG
public static final int AVG- See Also:
-
COUNT
public static final int COUNT- See Also:
-
-
Constructor Details
-
Aggregate
public Aggregate()
-
-
Method Details
-
checkArguments
Static analysis: prevent sorting of the argument- Overrides:
checkArguments
in classSystemFunction
- Parameters:
visitor
- the expression visitor- Throws:
XPathException
-
getItemType
Determine the item type of the value returned by the function- Overrides:
getItemType
in classSystemFunction
- Parameters:
th
- the type hierarchy cache- Returns:
- a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
-
computeCardinality
public int computeCardinality()Determine the cardinality of the function.- Overrides:
computeCardinality
in classSystemFunction
- Returns:
- the computed cardinality, as one of the values
StaticProperty.ALLOWS_ZERO_OR_ONE
,StaticProperty.EXACTLY_ONE
,StaticProperty.ALLOWS_ONE_OR_MORE
,StaticProperty.ALLOWS_ZERO_OR_MORE
-
evaluateItem
Evaluate the function- Specified by:
evaluateItem
in interfaceEvaluableItem
- Overrides:
evaluateItem
in classExpression
- Parameters:
context
- The context in which the expression is to be evaluated- Returns:
- the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
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 totalledcontext
- the XPath dynamic contextlocation
- 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.
- Throws:
XPathException
-
average
public static AtomicValue average(SequenceIterator iter, XPathContext context, SourceLocator location) throws XPathException Calculate average- Parameters:
iter
- iterator over the items to be totalledcontext
- the XPath dynamic contextlocation
- location of the expression in the source for diagnostics- Returns:
- the average of the values
- Throws:
XPathException
-
count
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
-
isCountFunction
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
-