Class CompareToStringConstant

All Implemented Interfaces:
ComparisonExpression, ExportAgent, Locatable, IdentityComparable, Traceable

public class CompareToStringConstant extends CompareToConstant
This class implements a comparison of a computed value to a string constant using one of the operators eq, ne, lt, gt, le, ge. The semantics are identical to ValueComparison, with code-point collation, but this is a fast path for an important common case.
  • Constructor Details

    • CompareToStringConstant

      public CompareToStringConstant(Expression operand, int operator, UnicodeString 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

    • getComparand

      public UnicodeString getComparand()
      Get the string value on the rhs of the expression
      Returns:
      the integer constant
    • getRhsExpression

      public Expression getRhsExpression()
      Get the effective right-hand-side expression (so that general logic for comparison expressions can be used)
      Specified by:
      getRhsExpression in interface ComparisonExpression
      Specified by:
      getRhsExpression in class CompareToConstant
      Returns:
      a Literal representing the RHS expression
    • copy

      public Expression copy(RebindingMap rebindings)
      Copy an expression. This makes a deep copy.
      Specified by:
      copy in class Expression
      Parameters:
      rebindings - variables that need to be re-bound
      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

      protected int computeHashCode()
      Hashcode supporting equals()
      Overrides:
      computeHashCode in class UnaryExpression
      Returns:
      a computed hash code
    • 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

      protected 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.
    • 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.
    • 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
      Returns:
      the comparer
    • getStringCollator

      public StringCollator getStringCollator()
      Get the StringCollator used to compare string values.
      Returns:
      the collator.
    • getElaborator

      public Elaborator getElaborator()
      Make an elaborator for this expression
      Overrides:
      getElaborator in class Expression
      Returns:
      a suitable elaborator