Package net.sf.saxon.expr
Class EquivalenceComparison
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.BinaryExpression
-
- net.sf.saxon.expr.EquivalenceComparison
-
- All Implemented Interfaces:
ComparisonExpression,ExportAgent,Locatable,IdentityComparable,Traceable
public class EquivalenceComparison extends BinaryExpression implements ComparisonExpression
Class to handle equivalence comparisons of singletons. This only handles equality comparison. It follows the rules used for grouping and for XQuery 3.0 switch expressions: - each operand must be zero or one atomic values - untypedAtomic is treated as string - non-comparable values are not equal (no type errors) - two empty sequences are equal to each other - two NaN values are equal to each other
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.BinaryExpression
operator
-
Fields 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
Constructors Constructor Description EquivalenceComparison(Expression p1, int operator, Expression p2)Create a singleton comparison - that is, a comparison between two singleton (0:1) sequences using the general comparison semantics
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcomputeCardinality()Determine the static cardinality.booleanconvertsUntypedToOther()Determine whether untyped atomic values should be converted to the type of the other operandExpressioncopy(RebindingMap rebindings)Copy an expression.booleaneffectiveBooleanValue(XPathContext context)Evaluate the expression in a boolean contextBooleanValueevaluateItem(XPathContext context)Evaluate the expression in a given contextprotected voidexplainExtraAttributes(ExpressionPresenter out)Add subclass-specific attributes to the expression tree explanation.AtomicComparergetAtomicComparer()Get the AtomicComparer used to compare atomic values.AtomicComparergetComparer()java.lang.StringgetExpressionName()Get a name identifying the kind of expression, in terms meaningful to a user.ItemTypegetItemType()Determine the data type of the expressionintgetSingletonOperator()Get the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGEbooleanisKnownToBeComparable()ExpressiontypeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)Type-check the expression.-
Methods inherited from class net.sf.saxon.expr.BinaryExpression
computeHashCode, computeSpecialProperties, displayOperator, equals, export, getImplementationMethod, getLhs, getLhsExpression, getOperandRole, getOperator, getRhs, getRhsExpression, isAssociative, isCommutative, isInverse, operands, optimize, setFlattened, setLhsExpression, setRhsExpression, tag, toShortString, toString
-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, dynamicError, evaluateAsString, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.expr.ComparisonExpression
getLhs, getLhsExpression, getRhs, getRhsExpression
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Constructor Detail
-
EquivalenceComparison
public EquivalenceComparison(Expression p1, int operator, Expression p2)
Create a singleton comparison - that is, a comparison between two singleton (0:1) sequences using the general comparison semantics- Parameters:
p1- the first operandoperator- the operatorp2- the second operand
-
-
Method Detail
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Type-check the expression. Default implementation for binary operators that accept any kind of operand- 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 original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
- Throws:
XPathException- if an error is discovered during this phase (typically a type error)
-
getAtomicComparer
public AtomicComparer getAtomicComparer()
Description copied from interface:ComparisonExpressionGet the AtomicComparer used to compare atomic values. This encapsulates any collation that is used- Specified by:
getAtomicComparerin interfaceComparisonExpression
-
getSingletonOperator
public int getSingletonOperator()
Description copied from interface:ComparisonExpressionGet the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGE- Specified by:
getSingletonOperatorin interfaceComparisonExpression
-
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
public 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.
-
getItemType
public ItemType getItemType()
Determine the data type of the expression- Specified by:
getItemTypein classExpression- Returns:
- Type.BOOLEAN
-
isKnownToBeComparable
public boolean isKnownToBeComparable()
-
getComparer
public AtomicComparer getComparer()
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copyin classExpression- Parameters:
rebindings-- Returns:
- the copy of the original expression
-
evaluateItem
public BooleanValue evaluateItem(XPathContext context) throws XPathException
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
public boolean effectiveBooleanValue(XPathContext context) throws XPathException
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
-
getExpressionName
public java.lang.String 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 export() output displaying the expression.
-
explainExtraAttributes
protected void explainExtraAttributes(ExpressionPresenter out)
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
-
-