net.sf.saxon.expr

Class ValueComparison

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

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

Field Summary

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

operand0, operand1, operator

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

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

ValueComparison(Expression p1, int op, Expression p2)
Create a relational expression identifying the two operands and the operator

Method Summary

int
computeCardinality()
Determine the static cardinality.
boolean
convertsUntypedToOther()
Determine whether untyped atomic values should be converted to the type of the other operand
Expression
copy()
Copy an expression.
protected String
displayOperator()
boolean
effectiveBooleanValue(XPathContext context)
Evaluate the effective boolean value of the expression
Item
evaluateItem(XPathContext context)
Evaluate the expression in a given context
AtomicComparer
getAtomicComparer()
Get the AtomicComparer used to compare atomic values.
ItemType
getItemType(TypeHierarchy th)
Determine the data type of the expression
BooleanValue
getResultWhenEmpty()
Get the result to be returned if one of the operands is an empty sequence
int
getSingletonOperator()
Get the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGE
boolean
isNegatable(ExpressionVisitor visitor)
Check whether this specific instance of the expression is negatable
boolean
needsRuntimeComparabilityCheck()
Determine whether a run-time check is needed to check that the types of the arguments are comparable
Expression
negate()
Return the negation of this value comparison: that is, a value comparison that returns true() if and only if the original returns false().
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
Perform optimisation of an expression and its subexpressions.
void
setResultWhenEmpty(BooleanValue value)
Set the result to be returned if one of the operands is an empty sequence
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression

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

computeCardinality, computeSpecialProperties, displayOperator, equals, explain, getOperands, getOperator, hashCode, isAssociative, isCommutative, isInverse, iterateSubExpressions, optimize, promote, replaceSubExpression, setFlattened, simplify, 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

Constructor Details

ValueComparison

public ValueComparison(Expression p1,
                       int op,
                       Expression p2)
Create a relational expression identifying the two operands and the operator
Parameters:
p1 - the left-hand operand
op - the operator, as a token returned by the Tokenizer (e.g. Token.LT)
p2 - the right-hand operand

Method Details

computeCardinality

public int computeCardinality()
Determine the static cardinality.
Overrides:
computeCardinality in interface BinaryExpression

convertsUntypedToOther

public boolean convertsUntypedToOther()
Determine whether untyped atomic values should be converted to the type of the other operand
Specified by:
convertsUntypedToOther in interface ComparisonExpression
Returns:
true if untyped values should be converted to the type of the other operand, false if they should be converted to strings.

copy

public Expression copy()
Copy an expression. This makes a deep copy.
Overrides:
copy in interface Expression
Returns:
the copy of the original expression

displayOperator

protected String displayOperator()
Overrides:
displayOperator in interface BinaryExpression

effectiveBooleanValue

public boolean effectiveBooleanValue(XPathContext context)
            throws XPathException
Evaluate the effective boolean value of the expression
Overrides:
effectiveBooleanValue in interface Expression
Parameters:
context - the given context for evaluation
Returns:
a boolean representing the result of the comparison of the two operands

evaluateItem

public Item evaluateItem(XPathContext context)
            throws XPathException
Evaluate the expression in a given context
Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in interface Expression
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

getAtomicComparer

public 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:
getAtomicComparer in interface ComparisonExpression

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the expression
Overrides:
getItemType in interface Expression
Parameters:
th - the type hierarchy cache
Returns:
Type.BOOLEAN

getResultWhenEmpty

public BooleanValue 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)

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:
getSingletonOperator in interface ComparisonExpression

isNegatable

public boolean isNegatable(ExpressionVisitor visitor)
Check whether this specific instance of the expression is negatable
Specified by:
isNegatable in interface Negatable
Returns:
true if it is

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

negate

public Expression 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 ().
Specified by:
negate in interface Negatable
Returns:
the inverted comparison

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:
optimize in interface BinaryExpression
Parameters:
visitor - an expression visitor
contextItemType - 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 to Type.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)

setResultWhenEmpty

public void setResultWhenEmpty(BooleanValue value)
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.

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
Type-check the expression
Overrides:
typeCheck in interface BinaryExpression