|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.jexl2.JexlArithmetic
public class JexlArithmetic
Perform arithmetic.
All arithmetic operators (+, - , *, /, %) follow the same rules regarding their arguments.
Field Summary | |
---|---|
protected static BigDecimal |
BIGD_DOUBLE_MAX_VALUE
Double.MAX_VALUE as BigDecimal. |
protected static BigDecimal |
BIGD_DOUBLE_MIN_VALUE
Double.MIN_VALUE as BigDecimal. |
protected static BigInteger |
BIGI_LONG_MAX_VALUE
Long.MAX_VALUE as BigInteger. |
protected static BigInteger |
BIGI_LONG_MIN_VALUE
Long.MIN_VALUE as BigInteger. |
Constructor Summary | |
---|---|
JexlArithmetic(boolean lenient)
Creates a JexlArithmetic. |
Method Summary | |
---|---|
Object |
add(Object left,
Object right)
Add two values together. |
protected Object |
controlNullNullOperands()
The result of +,/,-,*,% when both operands are null. |
protected void |
controlNullOperand()
Throw a NPE if arithmetic is strict. |
Object |
divide(Object left,
Object right)
Divide the left value by the right. |
boolean |
equals(Object left,
Object right)
Test if left and right are equal. |
boolean |
greaterThan(Object left,
Object right)
Test if left > right. |
boolean |
greaterThanOrEqual(Object left,
Object right)
Test if left >= right. |
protected boolean |
isFloatingPoint(Object o)
Is Object a floating point number. |
protected boolean |
isFloatingPointNumber(Object val)
Test if the passed value is a floating point number, i.e. |
protected boolean |
isFloatingPointType(Object left,
Object right)
Test if either left or right are either a Float or Double. |
boolean |
isLenient()
Checks whether this JexlArithmetic instance triggers errors during evaluation when null is used as an operand. |
protected boolean |
isNumberable(Object o)
Is Object a whole number. |
boolean |
lessThan(Object left,
Object right)
Test if left < right. |
boolean |
lessThanOrEqual(Object left,
Object right)
Test if left <= right. |
boolean |
matches(Object left,
Object right)
Test if left regexp matches right. |
Object |
mod(Object left,
Object right)
left value mod right. |
Object |
multiply(Object left,
Object right)
Multiply the left value by the right. |
Number |
narrow(Number original)
Given a Number, return back the value using the smallest type the result will fit into. |
protected boolean |
narrowArguments(Object[] args)
Replace all numbers in an arguments array with the smallest type that will fit. |
protected Object |
narrowArrayType(Object[] untyped)
Given an array of objects, attempt to type it more strictly. |
protected Number |
narrowBigInteger(Object lhs,
Object rhs,
BigInteger bigi)
Given a BigInteger, narrow it to an Integer or Long if it fits and the arguments class allow it. |
Object |
subtract(Object left,
Object right)
Subtract the right value from the left. |
BigDecimal |
toBigDecimal(Object val)
Get a BigDecimal from the object passed. |
BigInteger |
toBigInteger(Object val)
Get a BigInteger from the object passed. |
boolean |
toBoolean(Object val)
Coerce to a boolean (not a java.lang.Boolean). |
double |
toDouble(Object val)
Coerce to a double. |
int |
toInteger(Object val)
Coerce to a int. |
long |
toLong(Object val)
Coerce to a long (not a java.lang.Long). |
String |
toString(Object val)
Coerce to a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final BigDecimal BIGD_DOUBLE_MAX_VALUE
protected static final BigDecimal BIGD_DOUBLE_MIN_VALUE
protected static final BigInteger BIGI_LONG_MAX_VALUE
protected static final BigInteger BIGI_LONG_MIN_VALUE
Constructor Detail |
---|
public JexlArithmetic(boolean lenient)
lenient
- whether this arithmetic is lenient or strictMethod Detail |
---|
public boolean isLenient()
protected Object controlNullNullOperands()
NullPointerException
- if strictprotected void controlNullOperand()
NullPointerException
- if strictprotected boolean isFloatingPointType(Object left, Object right)
left
- one object to testright
- the other
protected boolean isFloatingPointNumber(Object val)
val
- the object to be tested
protected boolean isFloatingPoint(Object o)
o
- Object to be analyzed.
protected boolean isNumberable(Object o)
o
- Object to be analyzed.
protected Number narrowBigInteger(Object lhs, Object rhs, BigInteger bigi)
The rules are: if either arguments is a BigInteger, no narrowing will occur if either arguments is a Long, no narrowing to Integer will occur
lhs
- the left hand side operand that lead to the bigi resultrhs
- the right hand side operand that lead to the bigi resultbigi
- the BigInteger to narrow
protected Object narrowArrayType(Object[] untyped)
untyped
- an untyped array
protected boolean narrowArguments(Object[] args)
args
- the argument array
public Object add(Object left, Object right)
If any numeric add fails on coercion to the appropriate type, treat as Strings and do concatenation.
left
- first valueright
- second value
public Object divide(Object left, Object right)
left
- first valueright
- second value
ArithmeticException
- if right == 0public Object mod(Object left, Object right)
left
- first valueright
- second value
ArithmeticException
- if right == 0.0public Object multiply(Object left, Object right)
left
- first valueright
- second value
public Object subtract(Object left, Object right)
left
- first valueright
- second value
public boolean matches(Object left, Object right)
left
- first valueright
- second value
public boolean equals(Object left, Object right)
left
- first valueright
- second value
public boolean lessThan(Object left, Object right)
left
- first valueright
- second value
public boolean greaterThan(Object left, Object right)
left
- first valueright
- second value
public boolean lessThanOrEqual(Object left, Object right)
left
- first valueright
- second value
public boolean greaterThanOrEqual(Object left, Object right)
left
- first valueright
- second value
public boolean toBoolean(Object val)
val
- Object to be coerced.
public int toInteger(Object val)
val
- Object to be coerced.
public long toLong(Object val)
val
- Object to be coerced.
public BigInteger toBigInteger(Object val)
val
- the object to be coerced.
NullPointerException
- if val is null and mode is strict.public BigDecimal toBigDecimal(Object val)
val
- the object to be coerced.
NullPointerException
- if val is null and mode is strict.public double toDouble(Object val)
val
- Object to be coerced.
NullPointerException
- if val is null and mode is strict.public String toString(Object val)
val
- Object to be coerced.
NullPointerException
- if val is null and mode is strict.public Number narrow(Number original)
original
- the original number.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |