Class ELArithmetic
java.lang.Object
org.apache.el.lang.ELArithmetic
- Direct Known Subclasses:
ELArithmetic.BigDecimalDelegate, ELArithmetic.BigIntegerDelegate, ELArithmetic.DoubleDelegate, ELArithmetic.LongDelegate
A helper class of Arithmetic defined by the EL Specification.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classArithmetic delegate for BigDecimal operations.static final classArithmetic delegate for BigInteger operations.static final classArithmetic delegate for double/float operations.static final classArithmetic delegate for long/integer operations. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ELArithmetic.BigDecimalDelegateBigDecimal arithmetic delegate instance.static final ELArithmetic.BigIntegerDelegateBigInteger arithmetic delegate instance.static final ELArithmetic.DoubleDelegateDouble arithmetic delegate instance.static final ELArithmetic.LongDelegateLong arithmetic delegate instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract NumberAdd two numbers.static NumberAdd two objects, coercing them to the appropriate numeric type.protected abstract NumberCoerce a number to the delegate's preferred type.protected final NumberCoerce an object to a number.protected abstract NumberCoerce a string to a number.protected abstract NumberDivide two numbers.static NumberDivide two objects, coercing them to the appropriate numeric type.static booleanCheck if the given object is a number.static booleanisNumberType(Class<?> type) Check if the given class is a number type.protected abstract booleanCheck if this delegate matches the given operand types.protected abstract NumberCompute the modulo of two numbers.static NumberCompute the modulo of two objects, coercing them to the appropriate numeric type.protected abstract NumberMultiply two numbers.static NumberMultiply two objects, coercing them to the appropriate numeric type.protected abstract NumberSubtract two numbers.static NumberSubtract two objects, coercing them to the appropriate numeric type.
-
Field Details
-
BIGDECIMAL
BigDecimal arithmetic delegate instance. -
BIGINTEGER
BigInteger arithmetic delegate instance. -
DOUBLE
Double arithmetic delegate instance. -
LONG
Long arithmetic delegate instance.
-
-
Constructor Details
-
ELArithmetic
protected ELArithmetic()Protected constructor for subclasses.
-
-
Method Details
-
add
Add two objects, coercing them to the appropriate numeric type.- Parameters:
obj0- The first operandobj1- The second operand- Returns:
- The result of the addition
- Throws:
ELException- if the operands cannot be coerced to numbers or if the addition cannot be computed, for example overflow with extreme BigDecimal values
-
mod
Compute the modulo of two objects, coercing them to the appropriate numeric type.- Parameters:
obj0- The dividendobj1- The divisor- Returns:
- The result of the modulo operation
- Throws:
ELException- if the operands cannot be coerced to numbers or if the modulo cannot be computed, for example division by zero with integer operands
-
subtract
Subtract two objects, coercing them to the appropriate numeric type.- Parameters:
obj0- The minuendobj1- The subtrahend- Returns:
- The result of the subtraction
- Throws:
ELException- if the operands cannot be coerced to numbers or if the subtraction cannot be computed, for example overflow with extreme BigDecimal values
-
divide
Divide two objects, coercing them to the appropriate numeric type.- Parameters:
obj0- The dividendobj1- The divisor- Returns:
- The result of the division
- Throws:
ELException- if the operands cannot be coerced to numbers or if the division cannot be computed, for example division by zero with BigDecimal or BigInteger operands
-
multiply
Multiply two objects, coercing them to the appropriate numeric type.- Parameters:
obj0- The first factorobj1- The second factor- Returns:
- The result of the multiplication
- Throws:
ELException- if the operands cannot be coerced to numbers or if the multiplication cannot be computed, for example overflow with extreme BigDecimal values
-
isNumber
Check if the given object is a number.- Parameters:
obj- The object to check- Returns:
- true if the object is a number
-
isNumberType
Check if the given class is a number type.- Parameters:
type- The class to check- Returns:
- true if the class is a number type
-
add
-
multiply
-
subtract
-
mod
-
coerce
-
coerce
Coerce an object to a number.- Parameters:
obj- The object to coerce- Returns:
- The coerced number
- Throws:
ELException- if the object cannot be coerced to a number
-
coerce
-
divide
-
matches
-