Package net.sf.saxon.expr
Class Calculator
java.lang.Object
net.sf.saxon.expr.Calculator
- Direct Known Subclasses:
Calculator.AnyDivAny
,Calculator.AnyIdivAny
,Calculator.AnyMinusAny
,Calculator.AnyModAny
,Calculator.AnyPlusAny
,Calculator.AnyTimesAny
,Calculator.DecimalDivDecimal
,Calculator.DecimalIdivDecimal
,Calculator.DecimalMinusDecimal
,Calculator.DecimalModDecimal
,Calculator.DecimalPlusDecimal
,Calculator.DecimalTimesDecimal
,Calculator.DoubleDivDouble
,Calculator.DoubleMinusDouble
,Calculator.DoubleModDouble
,Calculator.DoublePlusDouble
,Calculator.DoubleTimesDouble
,Calculator.FloatDivFloat
,Calculator.FloatIdivFloat
,Calculator.FloatMinusFloat
,Calculator.FloatModFloat
,Calculator.FloatPlusFloat
,Calculator.FloatTimesFloat
,Calculator.IntegerDivInteger
,Calculator.IntegerIdivInteger
,Calculator.IntegerMinusInteger
,Calculator.IntegerModInteger
,Calculator.IntegerPlusInteger
,Calculator.IntegerTimesInteger
This class evaluates arithmetic expressions; it acts as a helper class to the ArithmeticExpression
class. There are many subclasses for the different kinds of arithmetic expression, and static methods
that allow the right subclass to be selected, either at compile time or at run time.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Arithmetic: anyAtomicType div AnyAtomicTypestatic class
Arithmetic: anyAtomicType idiv AnyAtomicTypestatic class
Arithmetic: anyAtomicType - AnyAtomicTypestatic class
Arithmetic: anyAtomicType mod AnyAtomicTypestatic class
Arithmetic: anyAtomicType + AnyAtomicTypestatic class
Arithmetic: anyAtomicType * AnyAtomicTypestatic class
Arithmetic: decimal div decimal (including types that promote to decimal, that is, integer)static class
Arithmetic: decimal idiv decimal (including types that promote to decimal, that is, integer)static class
Arithmetic: decimal - decimal (including types that promote to decimal, that is, integer)static class
Arithmetic: decimal mod decimal (including types that promote to decimal, that is, integer)static class
Arithmetic: decimal + decimal (including types that promote to decimal, that is, integer)static class
Arithmetic: decimal * decimal (including types that promote to decimal, that is, integer)static class
Arithmetic: double div double (including types that promote to double)static class
Arithmetic: double - double (including types that promote to double)static class
Arithmetic: double mod double (including types that promote to double)static interface
Marker interface for operations on doublesstatic class
Arithmetic: double + double (including types that promote to double)static class
Arithmetic: double * double (including types that promote to double)static class
Arithmetic: float div float (including types that promote to float)static class
Arithmetic: float idiv float (including types that promote to float)static class
Arithmetic: float - float (including types that promote to float)static class
Arithmetic: float mod float (including types that promote to float)static class
Arithmetic: float + float (including types that promote to float)static class
Arithmetic: float * float (including types that promote to float)static class
Arithmetic: integer div integerstatic class
Arithmetic: integer idiv integerstatic class
Arithmetic: integer - integerstatic class
Arithmetic: integer mod integerstatic class
Arithmetic: integer + integerstatic class
Arithmetic: integer * integer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Calculator[]
Calculators used for the six operators when the static type information does not allow a more specific calculator to be chosenstatic final Calculator[]
Calculators used when both operands are xs:dateTime, xs:date, or xs:timestatic final Calculator[]
Calculators used when the first operand is xs:dateTime, xs:date, or xs:time, and the second is a durationstatic final Calculator[]
static final Calculator[]
Calculators used when the first operand is a decimalstatic final Calculator[]
static final Calculator[]
static final int
static final Calculator[]
static final Calculator[]
Calculators used when the first operand is a doublestatic final Calculator[]
static final Calculator[]
static final Calculator[]
Calculators used when the second operand is xs:dateTime, xs:date, or xs:time, and the first is a durationstatic final Calculator[]
Calculators used when the both operands are durationsstatic final Calculator[]
Calculators used when the first operand is a duration and the second is numericstatic final Calculator[]
static final Calculator[]
Calculators used when the first operand is a floatstatic final Calculator[]
static final Calculator[]
static final int
static final Calculator[]
static final Calculator[]
Calculators used when the first operand is an integerstatic final Calculator[]
static final Calculator[]
static final int
static final int
static final Calculator[]
Calculators used when the second operand is a duration and the first is numericstatic final int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncode()
Get a short code to identify the calculator in expression export filesabstract AtomicValue
compute
(AtomicValue a, AtomicValue b, XPathContext c) Perform an arithmetic operationstatic BigDecimalValue
static Calculator
getCalculator
(int typeA, int typeB, int operator, boolean mustResolve) Factory method to get a calculator for a given combination of typesstatic String
getCalculatorSetName
(int typeA, int typeB) Get the name of the calculator set for a given combination of typesabstract AtomicType
getResultType
(AtomicType typeA, AtomicType typeB) Get the type of the result of the calculator, given arguments types typeA and typeBstatic int
getTokenFromOperator
(int operator) Get the token number corresponding to the operator numberstatic int
operatorFromCode
(char code) static Calculator
reconstructCalculator
(String code) Get a calculator given the short code used in the exported expression tree
-
Field Details
-
PLUS
public static final int PLUS- See Also:
-
MINUS
public static final int MINUS- See Also:
-
TIMES
public static final int TIMES- See Also:
-
DIV
public static final int DIV- See Also:
-
MOD
public static final int MOD- See Also:
-
IDIV
public static final int IDIV- See Also:
-
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
Calculators used when the first operand is a double -
DOUBLE_FLOAT
-
DOUBLE_DECIMAL
-
DOUBLE_INTEGER
-
FLOAT_DOUBLE
Calculators used when the first operand is a float -
FLOAT_FLOAT
-
FLOAT_DECIMAL
-
FLOAT_INTEGER
-
DECIMAL_DOUBLE
Calculators used when the first operand is a decimal -
DECIMAL_FLOAT
-
DECIMAL_DECIMAL
-
DECIMAL_INTEGER
-
INTEGER_DOUBLE
Calculators used when the first operand is an integer -
INTEGER_FLOAT
-
INTEGER_DECIMAL
-
INTEGER_INTEGER
-
DATETIME_DATETIME
Calculators used when both operands are xs:dateTime, xs:date, or xs:time -
DATETIME_DURATION
Calculators used when the first operand is xs:dateTime, xs:date, or xs:time, and the second is a duration -
DURATION_DATETIME
Calculators used when the second operand is xs:dateTime, xs:date, or xs:time, and the first is a duration -
DURATION_DURATION
Calculators used when the both operands are durations -
DURATION_NUMERIC
Calculators used when the first operand is a duration and the second is numeric -
NUMERIC_DURATION
Calculators used when the second operand is a duration and the first is numeric
-
-
Constructor Details
-
Calculator
public Calculator()
-
-
Method Details
-
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
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
Factory method to get a calculator for a given combination of types- Parameters:
typeA
- fingerprint of the primitive type of the first operandtypeB
- fingerprint of the primitive type of the second operandoperator
- the arithmetic operator in usemustResolve
- 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
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
Get the name of the calculator set for a given combination of types- Parameters:
typeA
- the fingerprint of the primitive type of the first operandtypeB
- 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
Get the type of the result of the calculator, given arguments types typeA and typeB- Parameters:
typeA
- the type of the first operandtypeB
- the type of the second operand- Returns:
- the type of the result
-
decimalDivide
- Throws:
XPathException
-