Package net.sf.saxon.expr
Class CompareToIntegerConstant
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.UnaryExpression
net.sf.saxon.expr.CompareToIntegerConstant
- All Implemented Interfaces:
ComparisonExpression,ExportAgent,Locatable,IdentityComparable
This class implements a comparison of a numeric value to an integer constant using one of the operators
eq, ne, lt, gt, le, ge. The semantics are identical to ValueComparison, but this is a fast path for an
important common case.
-
Field Summary
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
ConstructorsConstructorDescriptionCompareToIntegerConstant(Expression operand, int operator, long comparand) Create the expression -
Method Summary
Modifier and TypeMethodDescriptionintDetermine the static cardinality.intHashcode supporting equals()intGet the static properties of this expression (other than its type).booleanDetermine whether untyped atomic values should be converted to the type of the other operandcopy(RebindingMap rebindings) Copy an expression.booleaneffectiveBooleanValue(XPathContext context) Get the effective boolean value of the expression.booleanIs this expression the same as another expression?evaluateItem(XPathContext context) Evaluate an expression as a single item.voidexport(ExpressionPresenter destination) Diagnostic print of expression structure.Get the AtomicComparer used to compare atomic values.longGet the integer value on the rhs of the expressionintGet the comparison operatorGet a name identifying the kind of expression, in terms meaningful to a user.intAn implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().Determine the data type of the expression, if possible.getLhs()Get the two operands of the comparisonprotected OperandRoleGet the usage (in terms of streamability analysis) of the single operandgetRhs()intGet the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGEoptimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) Perform optimisation of an expression and its subexpressions.Produce a short string identifying the expression for use in error messagestoString()The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.Methods inherited from class net.sf.saxon.expr.UnaryExpression
displayOperator, getBaseExpression, getOperand, operands, setBaseExpression, typeCheckMethods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, dynamicError, evaluateAsString, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getConstructType, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, 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, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers
-
Constructor Details
-
CompareToIntegerConstant
Create the expression
-
-
Method Details
-
getOperandRole
Description copied from class:UnaryExpressionGet the usage (in terms of streamability analysis) of the single operand- Specified by:
getOperandRolein classUnaryExpression- Returns:
- the operand usage
-
getLhsExpression
- Specified by:
getLhsExpressionin interfaceComparisonExpression
-
getLhs
Description copied from interface:ComparisonExpressionGet the two operands of the comparison- Specified by:
getLhsin interfaceComparisonExpression
-
getRhsExpression
- Specified by:
getRhsExpressionin interfaceComparisonExpression
-
getRhs
- Specified by:
getRhsin interfaceComparisonExpression
-
getComparand
public long getComparand()Get the integer value on the rhs of the expression- Returns:
- the integer constant
-
getComparisonOperator
public int getComparisonOperator()Get the comparison operator -
getImplementationMethod
public int getImplementationMethod()An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.- Specified by:
getImplementationMethodin classExpression- Returns:
- the value
Expression.EVALUATE_METHOD
-
computeSpecialProperties
public int computeSpecialProperties()Description copied from class:UnaryExpressionGet the static properties of this expression (other than its type). The result is bit-signficant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.- Overrides:
computeSpecialPropertiesin classUnaryExpression- Returns:
- the special properties, as a bit-significant integer
-
copy
Copy an expression. This makes a deep copy.- Specified by:
copyin classExpression- Parameters:
rebindings-- Returns:
- the copy of the original expression
-
equals
Is this expression the same as another expression?- Overrides:
equalsin classUnaryExpression- Parameters:
other- the expression to be compared with this one- Returns:
- true if the two expressions are statically equivalent
-
computeHashCode
public int computeHashCode()Hashcode supporting equals()- Overrides:
computeHashCodein classUnaryExpression- Returns:
- a computed hash code
-
evaluateItem
Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.- Overrides:
evaluateItemin classExpression- Parameters:
context- The context in which the expression is to be evaluated- Returns:
- the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
- Throws:
XPathException- if any dynamic error occurs evaluating the expression
-
effectiveBooleanValue
Get the effective boolean value of the expression. This returns false if the value is the empty sequence, a zero-length string, a number equal to zero, or the boolean false. Otherwise it returns true.- Overrides:
effectiveBooleanValuein classExpression- Parameters:
context- The context in which the expression is to be evaluated- Returns:
- the effective boolean value
- Throws:
XPathException- if any dynamic error occurs evaluating the expression
-
computeCardinality
public int computeCardinality()Description copied from class:UnaryExpressionDetermine the static cardinality. Default implementation returns the cardinality of the operand- Overrides:
computeCardinalityin classUnaryExpression- 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.
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.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 classUnaryExpression- Parameters:
visitor- the expression visitorcontextInfo- 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)
-
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.
-
getItemType
Determine the data type of the expression, if possible. All expression return sequences, in general; this method determines the type of the items within the sequence, assuming that (a) this is known in advance, and (b) it is the same for all items in the sequence.This method should always return a result, though it may be the best approximation that is available at the time.
- Overrides:
getItemTypein classUnaryExpression- Returns:
- a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
-
export
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
exportin interfaceExportAgent- Overrides:
exportin classUnaryExpression- Parameters:
destination- the expression presenter used to display the structure- Throws:
XPathException- if the export fails, for example if an expression is found that won't work in the target environment.
-
toString
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.
For subclasses of Expression that represent XPath expressions, the result should always be a string that parses as an XPath 3.0 expression
- Overrides:
toStringin classUnaryExpression- Returns:
- a representation of the expression as a string
-
toShortString
Produce a short string identifying the expression for use in error messages- Overrides:
toShortStringin classUnaryExpression- Returns:
- a short string, sufficient to identify the expression
-
getAtomicComparer
Get the AtomicComparer used to compare atomic values. This encapsulates any collation that is used- 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.
-