Package net.sf.saxon.expr
Class ValueComparison
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.BinaryExpression
net.sf.saxon.expr.ValueComparison
- All Implemented Interfaces:
Serializable,SourceLocator,LocationProvider,SaxonLocator,ComparisonExpression,EvaluableItem,Negatable,SequenceIterable,InstructionInfo,Locator
public final class ValueComparison
extends BinaryExpression
implements ComparisonExpression, Negatable
ValueComparison: a boolean expression that compares two atomic values
for equals, not-equals, greater-than or less-than. Implements the operators
eq, ne, lt, le, gt, ge
- See Also:
-
Field Summary
Fields inherited from class net.sf.saxon.expr.BinaryExpression
operand0, operand1, operatorFields inherited from class net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, locationId, PROCESS_METHOD, staticProperties -
Constructor Summary
ConstructorsConstructorDescriptionValueComparison(Expression p1, int op, Expression p2) Create a relational expression identifying the two operands and the operator -
Method Summary
Modifier and TypeMethodDescriptionintDetermine the static cardinality.booleanDetermine whether untyped atomic values should be converted to the type of the other operandcopy()Copy an expression.protected StringbooleaneffectiveBooleanValue(XPathContext context) Evaluate the effective boolean value of the expressionevaluateItem(XPathContext context) Evaluate the expression in a given contextGet the AtomicComparer used to compare atomic values.Determine the data type of the expressionGet the result to be returned if one of the operands is an empty sequenceintGet the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGEbooleanisNegatable(ExpressionVisitor visitor) Check whether this specific instance of the expression is negatablebooleanDetermine whether a run-time check is needed to check that the types of the arguments are comparablenegate()Return the negation of this value comparison: that is, a value comparison that returns true() if and only if the original returns false().optimize(ExpressionVisitor visitor, ItemType contextItemType) Perform optimisation of an expression and its subexpressions.voidsetAtomicComparer(AtomicComparer comparer) Set the AtomicComparer used to compare atomic valuesvoidsetResultWhenEmpty(BooleanValue value) Set the result to be returned if one of the operands is an empty sequencetypeCheck(ExpressionVisitor visitor, ItemType contextItemType) Type-check the expressionMethods inherited from class net.sf.saxon.expr.BinaryExpression
computeSpecialProperties, equals, explain, getOperands, getOperator, hashCode, isAssociative, isCommutative, isInverse, iterateSubExpressions, promote, replaceSubExpression, setFlattened, simplify, toStringMethods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, display, doPromotion, dynamicError, 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, setLocationId, staticTypeCheck, suppressValidation, typeErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.expr.ComparisonExpression
getOperands
-
Constructor Details
-
ValueComparison
Create a relational expression identifying the two operands and the operator- Parameters:
p1- the left-hand operandop- the operator, as a token returned by the Tokenizer (e.g. Token.LT)p2- the right-hand operand
-
-
Method Details
-
setAtomicComparer
Set the AtomicComparer used to compare atomic values- Parameters:
comparer- the AtomicComparer
-
getAtomicComparer
Get the AtomicComparer used to compare atomic values. This encapsulates any collation that is used. Note that the comparer is always known at compile time.- Specified by:
getAtomicComparerin interfaceComparisonExpression
-
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
-
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.
-
setResultWhenEmpty
Set the result to be returned if one of the operands is an empty sequence- Parameters:
value- the result to be returned if an operand is empty. Supply null to mean the empty sequence.
-
getResultWhenEmpty
Get the result to be returned if one of the operands is an empty sequence- Returns:
- BooleanValue.TRUE, BooleanValue.FALSE, or null (meaning the empty sequence)
-
needsRuntimeComparabilityCheck
public boolean needsRuntimeComparabilityCheck()Determine whether a run-time check is needed to check that the types of the arguments are comparable- Returns:
- true if a run-time check is needed
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException Type-check the expression- Overrides:
typeCheckin classBinaryExpression- Parameters:
visitor- an expression visitorcontextItemType- 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 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)
-
optimize
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException Perform optimisation of an expression and its subexpressions.This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
- Overrides:
optimizein classBinaryExpression- Parameters:
visitor- an expression visitorcontextItemType- 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 original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException- if an error is discovered during this phase (typically a type error)
-
isNegatable
Check whether this specific instance of the expression is negatable- Specified by:
isNegatablein interfaceNegatable- Returns:
- true if it is
-
negate
Return the negation of this value comparison: that is, a value comparison that returns true() if and only if the original returns false(). The result must be the same as not(this) even in the case where one of the operands is (). -
copy
Copy an expression. This makes a deep copy.- Specified by:
copyin classExpression- Returns:
- the copy of the original expression
-
effectiveBooleanValue
Evaluate the effective boolean value of the expression- Overrides:
effectiveBooleanValuein classExpression- Parameters:
context- the given context for evaluation- Returns:
- a boolean representing the result of the comparison of the two operands
- Throws:
XPathException- if any dynamic error occurs evaluating the expression
-
evaluateItem
Evaluate the expression in a given context- Specified by:
evaluateItemin interfaceEvaluableItem- Overrides:
evaluateItemin classExpression- Parameters:
context- the given context for evaluation- Returns:
- a BooleanValue representing the result of the numeric comparison of the two operands, or null representing the empty sequence
- Throws:
XPathException- if any dynamic error occurs evaluating the expression
-
getItemType
Determine the data type of the expression- Specified by:
getItemTypein classExpression- Parameters:
th- the type hierarchy cache- Returns:
- Type.BOOLEAN
-
computeCardinality
public int computeCardinality()Determine the static cardinality.- 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
-
displayOperator
- Overrides:
displayOperatorin classBinaryExpression
-