Package net.sf.saxon.expr
Class GeneralComparison
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.BinaryExpression
net.sf.saxon.expr.GeneralComparison
- All Implemented Interfaces:
ComparisonExpression,ExportAgent,Locatable,IdentityComparable,Traceable
- Direct Known Subclasses:
GeneralComparison20,GeneralEqualityEE
GeneralComparison: a boolean expression that compares two expressions
for equals, not-equals, greater-than or less-than. This implements the operators
=, !=, <, >, etc. This implementation is not used when in backwards-compatible mode
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic classElaborator for a general comparison expression such as (A = B). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AtomicComparerprotected GeneralComparison.ComparisonCardinalityprotected booleanprotected booleanprotected intFields inherited from class net.sf.saxon.expr.BinaryExpression
operatorFields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD -
Constructor Summary
ConstructorsConstructorDescriptionGeneralComparison(Expression p0, int op, Expression p1) Create a relational expression identifying the two operands and the operator -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancompare(AtomicValue a0, int operator, AtomicValue a1, AtomicComparer comparer, boolean checkTypes, XPathContext context, NamespaceResolver nsResolver) Compare two atomic valuesprotected intDetermine the static cardinality.protected intGet a hashCode for comparing two expressions.booleanDetermine whether untyped atomic values should be converted to the type of the other operandbooleaneffectiveBooleanValue(XPathContext context) Evaluate the expression in a boolean contextbooleanIs this expression the same as another expression?evaluateItem(XPathContext context) Evaluate the expression in a given contextprotected voidAdd subclass-specific attributes to the expression tree explanation.Get the AtomicComparer used to compare atomic values.Ask whether the comparison is known to be many-to-one, one-to-one, or many-to-many.static intReturn the singleton form of the comparison operator, e.g.Make an elaborator for this expressionGet a name identifying the kind of expression, in terms meaningful to a user.intDetermine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.protected GeneralComparisonDetermine the data type of the expressionGet the namespace context for this expression, needed in the event that one operand contains untyped atomic values and the other contains QNamesintGet the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGEgetStaticUType(UType contextItemType) Get the static type of the expression as a UType, following precisely the type inference rules defined in the XSLT 3.0 specification.Get the (partial) name of a class that supports streaming of this kind of expressionGet the StringCollator used to compare string values.booleanAsk whether a runtime check of the types of the operands is neededoptimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) Optimize the expressionvoidsetAtomicComparer(AtomicComparer comparer) Set the comparer to be usedvoidSay whether the comparison is known to be many-to-one, one-to-one, or many-to-many.voidsetNeedsRuntimeCheck(boolean needsCheck) Say whether a runtime check of the types of the operands is neededprotected Stringtag()Get the element name used to identify this expression in exported expression formattypeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) Type-check the expressionMethods inherited from class net.sf.saxon.expr.BinaryExpression
computeSpecialProperties, displayOperator, export, getImplementationMethod, getLhs, getLhsExpression, getOperandRole, getOperator, getRhs, getRhsExpression, isAssociative, isCommutative, isInverse, operands, setFlattened, setLhsExpression, setRhsExpression, toShortString, toStringMethods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, copy, dispatchTailCall, dynamicError, evaluateAsString, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocationMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.expr.ComparisonExpression
getLhs, getLhsExpression, getRhs, getRhsExpressionMethods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
Field Details
-
singletonOperator
protected int singletonOperator -
comparer
-
runtimeCheckNeeded
protected boolean runtimeCheckNeeded -
comparisonCardinality
-
doneWarnings
protected boolean doneWarnings
-
-
Constructor Details
-
GeneralComparison
Create a relational expression identifying the two operands and the operator- Parameters:
p0- the left-hand operandop- the operator, as a token returned by the Tokenizer (e.g. Token.LT)p1- the right-hand operand
-
-
Method Details
-
needsRuntimeCheck
public boolean needsRuntimeCheck()Ask whether a runtime check of the types of the operands is needed- Returns:
- true if the types of the operands need to be checked at run-time
-
setNeedsRuntimeCheck
public void setNeedsRuntimeCheck(boolean needsCheck) Say whether a runtime check of the types of the operands is needed- Parameters:
needsCheck- true if the types of the operands need to be checked at run-time
-
getComparisonCardinality
Ask whether the comparison is known to be many-to-one, one-to-one, or many-to-many. (Note, an expression that is one-to-many will be converted to one that is many-to-one).- Returns:
- the Cardinality of the comparison as one of the values
GeneralComparison.ComparisonCardinality.ONE_TO_ONE,GeneralComparison.ComparisonCardinality.MANY_TO_MANY,GeneralComparison.ComparisonCardinality.MANY_TO_ONE
-
setComparisonCardinality
Say whether the comparison is known to be many-to-one, one-to-one, or many-to-many.- Parameters:
card- the Cardinality of the comparison as one of the valuesGeneralComparison.ComparisonCardinality.ONE_TO_ONE,GeneralComparison.ComparisonCardinality.MANY_TO_MANY,GeneralComparison.ComparisonCardinality.MANY_TO_ONE
-
setAtomicComparer
Set the comparer to be used- Parameters:
comparer- the comparer to be used
-
getExpressionName
Get a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
getExpressionNamein classExpression- Returns:
- a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in explain() output displaying the expression.
-
getNamespaceResolver
Get the namespace context for this expression, needed in the event that one operand contains untyped atomic values and the other contains QNames- Returns:
- the resolver used for namespace prefix resolution
-
getAtomicComparer
Get the AtomicComparer used to compare atomic values. This encapsulates any collation that is used- Specified by:
getAtomicComparerin interfaceComparisonExpression- Returns:
- the comparer
-
getStringCollator
Get the StringCollator used to compare string values.- Specified by:
getStringCollatorin interfaceComparisonExpression- Returns:
- the collator. May return null if the expression will never be used to compare strings
-
getSingletonOperator
public int getSingletonOperator()Get the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGE- Specified by:
getSingletonOperatorin interfaceComparisonExpression- Returns:
- the operator, as defined in class
Token
-
convertsUntypedToOther
public boolean convertsUntypedToOther()Determine whether untyped atomic values should be converted to the type of the other operand- Specified by:
convertsUntypedToOtherin interfaceComparisonExpression- Returns:
- true if untyped values should be converted to the type of the other operand, false if they should be converted to strings.
-
computeCardinality
protected int computeCardinality()Determine the static cardinality. Returns [1..1]- Overrides:
computeCardinalityin classBinaryExpression- 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. May also returnStaticProperty.ALLOWS_ZEROif the result is known to be an empty sequence, orStaticProperty.ALLOWS_MANYif if is known to return a sequence of length two or more.
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException Type-check the expression- Overrides:
typeCheckin classBinaryExpression- Parameters:
visitor- an expression visitorcontextInfo- Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.- Returns:
- the checked expression
- Throws:
XPathException- if an error is discovered during this phase (typically a type error)
-
getIntrinsicDependencies
public int getIntrinsicDependencies()Description copied from class:ExpressionDetermine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. For example, position() has an intrinsic dependency on the context position, while (position()+1) does not. The default implementation of the method returns 0, indicating "no dependencies".- Overrides:
getIntrinsicDependenciesin classExpression- Returns:
- an integer containing bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
-
equals
Description copied from class:BinaryExpressionIs this expression the same as another expression?- Overrides:
equalsin classBinaryExpression- Parameters:
other- the other operand; the result is false if this is not an Expression- Returns:
- true if the other operand is an expression and if it can be determined that the two expressions are equivalent, in the sense that they will always return the same result.
-
computeHashCode
protected int computeHashCode()Get a hashCode for comparing two expressions. Note that this hashcode gives the same result for (A op B) and for (B op A), whether or not the operator is commutative.- Overrides:
computeHashCodein classBinaryExpression- Returns:
- a computed hash code
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException Optimize the expression- Overrides:
optimizein classBinaryExpression- Parameters:
visitor- an expression visitorcontextInfo- the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set toType.ITEM_TYPE- Returns:
- the checked expression
- Throws:
XPathException- if an error is discovered during this phase (typically a type error)
-
evaluateItem
Evaluate the expression in a given context- Overrides:
evaluateItemin classExpression- Parameters:
context- the given context for evaluation- Returns:
- a BooleanValue representing the result of the numeric comparison of the two operands
- Throws:
XPathException- if any dynamic error occurs evaluating the expression
-
effectiveBooleanValue
Evaluate the expression in a boolean context- Overrides:
effectiveBooleanValuein classExpression- Parameters:
context- the given context for evaluation- Returns:
- a boolean representing the result of the numeric comparison of the two operands
- Throws:
XPathException- if any dynamic error occurs evaluating the expression
-
compare
public static boolean compare(AtomicValue a0, int operator, AtomicValue a1, AtomicComparer comparer, boolean checkTypes, XPathContext context, NamespaceResolver nsResolver) throws XPathException Compare two atomic values- Parameters:
a0- the first valueoperator- the singleton version of the comparison operator, for exampleToken.FEQa1- the second valuecomparer- the comparer to be used to perform the comparison. If the comparer is context-sensitive then the context must already have been bound using comparer.provideContext().checkTypes- set to true if the operand types need to be checked for comparability at runtimecontext- the XPath evaluation contextnsResolver- namespace resolver- Returns:
- true if the comparison succeeds
- Throws:
XPathException- if a dynamic error occurs during the comparison
-
getItemType
Determine the data type of the expression- Specified by:
getItemTypein classExpression- Returns:
- the value BuiltInAtomicType.BOOLEAN
-
getStaticUType
Get the static type of the expression as a UType, following precisely the type inference rules defined in the XSLT 3.0 specification.- Overrides:
getStaticUTypein classExpression- Parameters:
contextItemType- static information about the context item- Returns:
- the static item type of the expression according to the XSLT 3.0 defined rules
-
getCorrespondingSingletonOperator
public static int getCorrespondingSingletonOperator(int op) Return the singleton form of the comparison operator, e.g. FEQ for EQUALS, FGT for GT -
getInverseComparison
-
getStreamerName
Get the (partial) name of a class that supports streaming of this kind of expression- Overrides:
getStreamerNamein classExpression- Returns:
- the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
-
tag
Get the element name used to identify this expression in exported expression format- Overrides:
tagin classBinaryExpression- Returns:
- the element name used to identify this expression
-
explainExtraAttributes
Description copied from class:BinaryExpressionAdd subclass-specific attributes to the expression tree explanation. Default implementation does nothing; this is provided for subclasses to override.- Overrides:
explainExtraAttributesin classBinaryExpression- Parameters:
out- the output destination for the displayed expression tree
-
getElaborator
Make an elaborator for this expression- Overrides:
getElaboratorin classExpression- Returns:
- a suitable elaborator
-