Class Calculator

    • Field Detail

      • ANY_ANY

        public static final Calculator[] ANY_ANY
        Calculators used for the six operators when the static type information does not allow a more specific calculator to be chosen
      • DOUBLE_DOUBLE

        public static final Calculator[] DOUBLE_DOUBLE
        Calculators used when the first operand is a double
      • DOUBLE_FLOAT

        public static final Calculator[] DOUBLE_FLOAT
      • DOUBLE_DECIMAL

        public static final Calculator[] DOUBLE_DECIMAL
      • DOUBLE_INTEGER

        public static final Calculator[] DOUBLE_INTEGER
      • FLOAT_DOUBLE

        public static final Calculator[] FLOAT_DOUBLE
        Calculators used when the first operand is a float
      • FLOAT_FLOAT

        public static final Calculator[] FLOAT_FLOAT
      • FLOAT_DECIMAL

        public static final Calculator[] FLOAT_DECIMAL
      • FLOAT_INTEGER

        public static final Calculator[] FLOAT_INTEGER
      • DECIMAL_DOUBLE

        public static final Calculator[] DECIMAL_DOUBLE
        Calculators used when the first operand is a decimal
      • DECIMAL_FLOAT

        public static final Calculator[] DECIMAL_FLOAT
      • DECIMAL_DECIMAL

        public static final Calculator[] DECIMAL_DECIMAL
      • DECIMAL_INTEGER

        public static final Calculator[] DECIMAL_INTEGER
      • INTEGER_DOUBLE

        public static final Calculator[] INTEGER_DOUBLE
        Calculators used when the first operand is an integer
      • INTEGER_FLOAT

        public static final Calculator[] INTEGER_FLOAT
      • INTEGER_DECIMAL

        public static final Calculator[] INTEGER_DECIMAL
      • INTEGER_INTEGER

        public static final Calculator[] INTEGER_INTEGER
      • DATETIME_DATETIME

        public static final Calculator[] DATETIME_DATETIME
        Calculators used when both operands are xs:dateTime, xs:date, or xs:time
      • DATETIME_DURATION

        public static final Calculator[] DATETIME_DURATION
        Calculators used when the first operand is xs:dateTime, xs:date, or xs:time, and the second is a duration
      • DURATION_DATETIME

        public static final Calculator[] DURATION_DATETIME
        Calculators used when the second operand is xs:dateTime, xs:date, or xs:time, and the first is a duration
      • DURATION_DURATION

        public static final Calculator[] DURATION_DURATION
        Calculators used when the both operands are durations
      • DURATION_NUMERIC

        public static final Calculator[] DURATION_NUMERIC
        Calculators used when the first operand is a duration and the second is numeric
      • NUMERIC_DURATION

        public static final Calculator[] NUMERIC_DURATION
        Calculators used when the second operand is a duration and the first is numeric
    • Constructor Detail

      • Calculator

        public Calculator()
    • Method Detail

      • getTokenFromOperator

        public static int getTokenFromOperator​(int operator)
        Get the token number corresponding to the operator number
        Parameters:
        operator - the Calculator operator code
        Returns:
        the corresponding token
      • code

        public java.lang.String code()
        Get a short code to identify the calculator in expression export files
        Returns:
        a short identifying code that can be used to reconstruct the calculator
      • getCalculator

        public static Calculator getCalculator​(int typeA,
                                               int typeB,
                                               int operator,
                                               boolean mustResolve)
        Factory method to get a calculator for a given combination of types
        Parameters:
        typeA - fingerprint of the primitive type of the first operand
        typeB - fingerprint of the primitive type of the second operand
        operator - the arithmetic operator in use
        mustResolve - indicates that a concrete Calculator is required (rather than an ANY_ANY calculator which needs to be further resolved at run-time)
        Returns:
        null if no suitable Calculator can be found.
      • reconstructCalculator

        public static Calculator reconstructCalculator​(java.lang.String code)
        Get a calculator given the short code used in the exported expression tree
        Parameters:
        code - the short code, e.g. i+i for IntegerPlusInteger
        Returns:
        the appropriate Calculator
      • operatorFromCode

        public static int operatorFromCode​(char code)
      • getCalculatorSetName

        public static java.lang.String getCalculatorSetName​(int typeA,
                                                            int typeB)
        Get the name of the calculator set for a given combination of types
        Parameters:
        typeA - the fingerprint of the primitive type of the first operand
        typeB - the fingerprint of the primitive type of the second operand
        Returns:
        null if no suitable Calculator can be found.
      • compute

        public abstract AtomicValue compute​(AtomicValue a,
                                            AtomicValue b,
                                            XPathContext c)
                                     throws XPathException
        Perform an arithmetic operation
        Parameters:
        a - the first operand. Must not be null, and must be an instance of the type implied by the class name.
        b - the second operand. Must not be null, and must be an instance of the type implied by the class name.
        c - the XPath dynamic evaluation context
        Returns:
        the result of the computation, as a value of the correct primitive type
        Throws:
        XPathException - in the event of an arithmetic error
      • getResultType

        public abstract AtomicType getResultType​(AtomicType typeA,
                                                 AtomicType typeB)
        Get the type of the result of the calculator, given arguments types typeA and typeB
        Parameters:
        typeA - the type of the first operand
        typeB - the type of the second operand
        Returns:
        the type of the result