Class CompareToIntegerConstant

All Implemented Interfaces:
ComparisonExpression, ExportAgent, Locatable, IdentityComparable

public class CompareToIntegerConstant extends UnaryExpression implements ComparisonExpression
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.
  • Constructor Details

    • CompareToIntegerConstant

      public CompareToIntegerConstant(Expression operand, int operator, long comparand)
      Create the expression
      Parameters:
      operand - the operand to be compared with an integer constant. This must have a static type of NUMERIC, and a cardinality of EXACTLY ONE
      operator - the comparison operator, one of Token.FEQ, Token.FNE, Token.FGE, Token.FGT, Token.FLE, Token.FLT
      comparand - the integer constant
  • Method Details

    • getOperandRole

      protected OperandRole getOperandRole()
      Description copied from class: UnaryExpression
      Get the usage (in terms of streamability analysis) of the single operand
      Specified by:
      getOperandRole in class UnaryExpression
      Returns:
      the operand usage
    • getLhsExpression

      public Expression getLhsExpression()
      Specified by:
      getLhsExpression in interface ComparisonExpression
    • getLhs

      public Operand getLhs()
      Description copied from interface: ComparisonExpression
      Get the two operands of the comparison
      Specified by:
      getLhs in interface ComparisonExpression
    • getRhsExpression

      public Expression getRhsExpression()
      Specified by:
      getRhsExpression in interface ComparisonExpression
    • getRhs

      public Operand getRhs()
      Specified by:
      getRhs in interface ComparisonExpression
    • 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
      Returns:
      one of Token.FEQ, Token.FNE, Token.FGE, Token.FGT, Token.FLE, Token.FLT
    • 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:
      getImplementationMethod in class Expression
      Returns:
      the value Expression.EVALUATE_METHOD
    • computeSpecialProperties

      public int computeSpecialProperties()
      Description copied from class: UnaryExpression
      Get 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:
      computeSpecialProperties in class UnaryExpression
      Returns:
      the special properties, as a bit-significant integer
    • copy

      public Expression copy(RebindingMap rebindings)
      Copy an expression. This makes a deep copy.
      Specified by:
      copy in class Expression
      Parameters:
      rebindings -
      Returns:
      the copy of the original expression
    • equals

      public boolean equals(Object other)
      Is this expression the same as another expression?
      Overrides:
      equals in class UnaryExpression
      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:
      computeHashCode in class UnaryExpression
      Returns:
      a computed hash code
    • evaluateItem

      public BooleanValue evaluateItem(XPathContext context) throws XPathException
      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:
      evaluateItem in class Expression
      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

      public boolean effectiveBooleanValue(XPathContext context) throws XPathException
      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:
      effectiveBooleanValue in class Expression
      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: UnaryExpression
      Determine the static cardinality. Default implementation returns the cardinality of the operand
      Overrides:
      computeCardinality in class UnaryExpression
      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 return StaticProperty.ALLOWS_ZERO if the result is known to be an empty sequence, or StaticProperty.ALLOWS_MANY if 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:
      optimize in class UnaryExpression
      Parameters:
      visitor - the expression visitor
      contextInfo - 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)
    • getExpressionName

      public String getExpressionName()
      Get a name identifying the kind of expression, in terms meaningful to a user.
      Overrides:
      getExpressionName in class Expression
      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

      public ItemType 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:
      getItemType in class UnaryExpression
      Returns:
      a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
    • export

      public void export(ExpressionPresenter destination) throws XPathException
      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
      export in interface ExportAgent
      Overrides:
      export in class UnaryExpression
      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

      public String 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:
      toString in class UnaryExpression
      Returns:
      a representation of the expression as a string
    • toShortString

      public String toShortString()
      Produce a short string identifying the expression for use in error messages
      Overrides:
      toShortString in class UnaryExpression
      Returns:
      a short string, sufficient to identify the expression
    • 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
    • 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
    • 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.