net.sf.saxon.expr

Class GeneralComparison

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 AtomicComparercomparer
protected intsingletonOperator
Constructor Summary
GeneralComparison(Expression p0, int op, Expression p1)
Create a relational expression identifying the two operands and the operator
Method Summary
protected static booleancompare(AtomicValue a1, int operator, AtomicValue a2, AtomicComparer comparer, boolean checkTypes, XPathContext context)
Compare two atomic values
intcomputeCardinality()
Determine the static cardinality.
booleanconvertsUntypedToOther()
Determine whether untyped atomic values should be converted to the type of the other operand
Expressioncopy()
Copy an expression.
booleaneffectiveBooleanValue(XPathContext context)
Evaluate the expression in a boolean context
ItemevaluateItem(XPathContext context)
Evaluate the expression in a given context
protected voidexplainExtraAttributes(ExpressionPresenter out)
AtomicComparergetAtomicComparer()
Get the AtomicComparer used to compare atomic values.
protected GeneralComparisongetInverseComparison()
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the expression
intgetSingletonOperator()
Get the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGE
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression

Field Detail

comparer

protected AtomicComparer comparer

singletonOperator

protected int singletonOperator

Constructor Detail

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 Detail

compare

protected static boolean compare(AtomicValue a1, int operator, AtomicValue a2, AtomicComparer comparer, boolean checkTypes, XPathContext context)
Compare two atomic values

Parameters: a1 the first value operator the operator, for example EQUALS a2 the second value comparer the comparer to be used to perform the comparison checkTypes set to true if the operand types need to be checked for comparability at runtime context the XPath evaluation context @return true if the comparison succeeds

computeCardinality

public int computeCardinality()
Determine the static cardinality. Returns [1..1]

convertsUntypedToOther

public boolean convertsUntypedToOther()
Determine whether untyped atomic values should be converted to the type of the other operand

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.

Returns: the copy of the original expression

effectiveBooleanValue

public boolean effectiveBooleanValue(XPathContext context)
Evaluate the expression in a boolean context

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)
Evaluate the expression in a given context

Parameters: context the given context for evaluation

Returns: a BooleanValue representing the result of the numeric comparison of the two operands

explainExtraAttributes

protected void explainExtraAttributes(ExpressionPresenter out)

getAtomicComparer

public AtomicComparer getAtomicComparer()
Get the AtomicComparer used to compare atomic values. This encapsulates any collation that is used

getInverseComparison

protected GeneralComparison getInverseComparison()

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the 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

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression

Returns: the checked expression

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression

Returns: the checked expression