Class SwitchCaseComparison

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

    public class SwitchCaseComparison
    extends BinaryExpression
    implements ComparisonExpression
    Class to handle comparisons for XQuery switch expressions. This only handles equality comparison. It implements the rules used for XQuery 3.0 switch expressions: - each operand must be zero or one atomic values - untypedAtomic is treated as string - non-comparable values are not equal (no type errors) - two empty sequences are equal to each other - two NaN values are equal to each other In 4.0 this is extended so the second operand can contain multiple values, and the result is true if any of them match.
    • Constructor Detail

      • SwitchCaseComparison

        public SwitchCaseComparison​(Expression p1,
                                    int operator,
                                    Expression p2,
                                    boolean allowMultiple)
        Create a singleton comparison - that is, a comparison between two singleton (0:1) sequences using the general comparison semantics
        Parameters:
        p1 - the first operand
        operator - the operator
        p2 - the second operand
        allowMultiple - true if the 4.0 semantics are implemented (second operand may be a sequence)
    • Method Detail

      • typeCheck

        public Expression typeCheck​(ExpressionVisitor visitor,
                                    ContextItemStaticInfo contextInfo)
                             throws XPathException
        Type-check the expression. Default implementation for binary operators that accept any kind of operand
        Overrides:
        typeCheck in class BinaryExpression
        Parameters:
        visitor - an expression visitor
        contextInfo - Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.
        Returns:
        the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
        Throws:
        XPathException - if an error is discovered during this phase (typically a type error)
      • getStringCollator

        public StringCollator getStringCollator()
        Get the StringCollator used to compare string values.
        Specified by:
        getStringCollator in interface ComparisonExpression
        Returns:
        the collator. May return null if the expression will never be used to compare strings
      • getSingletonOperator

        public int getSingletonOperator()
        Description copied from interface: ComparisonExpression
        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.
      • getItemType

        public ItemType getItemType()
        Determine the data type of the expression
        Specified by:
        getItemType in class Expression
        Returns:
        Type.BOOLEAN
      • isKnownToBeComparable

        public boolean isKnownToBeComparable()
      • copy

        public Expression copy​(RebindingMap rebindings)
        Copy an expression. This makes a deep copy.
        Specified by:
        copy in class Expression
        Parameters:
        rebindings - variables that must be re-bound
        Returns:
        the copy of the original expression
      • evaluateItem

        public BooleanValue evaluateItem​(XPathContext context)
                                  throws XPathException
        Evaluate the expression in a given context
        Overrides:
        evaluateItem in class Expression
        Parameters:
        context - the given context for evaluation
        Returns:
        a BooleanValue representing the result of the numeric comparison of the two operands
        Throws:
        XPathException - if any dynamic error occurs evaluating the expression
      • effectiveBooleanValue

        public boolean effectiveBooleanValue​(XPathContext context)
                                      throws XPathException
        Evaluate the expression in a boolean context
        Overrides:
        effectiveBooleanValue in class Expression
        Parameters:
        context - the given context for evaluation
        Returns:
        a boolean representing the result of the numeric comparison of the two operands
        Throws:
        XPathException - if any dynamic error occurs evaluating the expression
      • getExpressionName

        public java.lang.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.
      • explainExtraAttributes

        protected void explainExtraAttributes​(ExpressionPresenter out)
        Description copied from class: BinaryExpression
        Add subclass-specific attributes to the expression tree explanation. Default implementation does nothing; this is provided for subclasses to override.
        Overrides:
        explainExtraAttributes in class BinaryExpression
        Parameters:
        out - the output destination for the displayed expression tree