net.sf.saxon.expr

Class GeneralComparison

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

public class GeneralComparison
extends BinaryExpression
implements ComparisonExpression

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

Field Summary

protected AtomicComparer
comparer
protected int
singletonOperator

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

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

Method Summary

protected static boolean
compare(AtomicValue a1, int operator, AtomicValue a2, AtomicComparer comparer, XPathContext context)
Compare two atomic values
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 expression in a boolean context
Item
evaluateItem(XPathContext context)
Evaluate the expression in a given context
AtomicComparer
getAtomicComparer()
Get the AtomicComparer used to compare atomic values.
protected GeneralComparison
getInverseComparison()
ItemType
getItemType(TypeHierarchy th)
Determine the data type of the expression
int
getSingletonOperator()
Get the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGE
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression
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

Field Details

comparer

protected AtomicComparer comparer

singletonOperator

protected int singletonOperator

Constructor Details

GeneralComparison

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

Method Details

compare

protected static boolean compare(AtomicValue a1,
                                 int operator,
                                 AtomicValue a2,
                                 AtomicComparer comparer,
                                 XPathContext context)
            throws XPathException
Compare two atomic values
Parameters:
a1 - the first value
operator - the operator, for example Token.EQUALS
a2 - the second value
comparer - the comparer to be used to perform the comparison
context - the XPath evaluation context
Returns:
true if the comparison succeeds

computeCardinality

public int computeCardinality()
Determine the static cardinality. Returns [1..1]
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 expression in a boolean context
Overrides:
effectiveBooleanValue in interface Expression
Parameters:
context - the given context for evaluation
Returns:
a boolean representing the result of the numeric 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

getAtomicComparer

public AtomicComparer getAtomicComparer()
Get the AtomicComparer used to compare atomic values. This encapsulates any collation that is used
Specified by:
getAtomicComparer in interface ComparisonExpression

getInverseComparison

protected GeneralComparison getInverseComparison()

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:
the value BuiltInAtomicType.BOOLEAN

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

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
            throws XPathException
Optimize the expression
Overrides:
optimize in interface BinaryExpression
Returns:
the checked expression

typeCheck

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