Class CompareToConstant

All Implemented Interfaces:
ComparisonExpression, ExportAgent, Locatable, IdentityComparable, Traceable
Direct Known Subclasses:
CompareToIntegerConstant, CompareToStringConstant

public abstract class CompareToConstant extends UnaryExpression implements ComparisonExpression
This class implements a comparison of a computed value to a literal 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. Different subclasses handle different types of constant.
  • Field Details

    • operator

      protected int operator
  • Constructor Details

    • CompareToConstant

      public CompareToConstant(Expression p0)
  • 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()
      Description copied from interface: ComparisonExpression
      Get the left-hand expression
      Specified by:
      getLhsExpression in interface ComparisonExpression
      Returns:
      the first operand expression
    • getLhs

      public Operand getLhs()
      Description copied from interface: ComparisonExpression
      Get the left-hand operand of the comparison
      Specified by:
      getLhs in interface ComparisonExpression
      Returns:
      the first operand
    • getRhsExpression

      public abstract Expression getRhsExpression()
      Description copied from interface: ComparisonExpression
      Get the right-hand expression
      Specified by:
      getRhsExpression in interface ComparisonExpression
      Returns:
      the second operand expression
    • getRhs

      public Operand getRhs()
      Description copied from interface: ComparisonExpression
      Get the right-hand operand of the comparison
      Specified by:
      getRhs in interface ComparisonExpression
      Returns:
      the second operand
    • 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

      protected 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
    • 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
    • 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)
    • 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)
    • 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
      Returns:
      the operator, as defined in class Token
    • 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.
    • interpretComparisonResult

      public static boolean interpretComparisonResult(int operator, int c)
      Interpret the result of the comparison
      Parameters:
      operator - the operator for example Token.FEQ or Token.FLE
      c - -1, 0, or +1, depending on how the operands compare
      Returns:
      true or false depending on the operator in use