|
||||||||||
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 java.math.BigDecimal |
BIGD_DOUBLE_MAX_VALUE
Double.MAX_VALUE as BigDecimal. |
protected static java.math.BigDecimal |
BIGD_DOUBLE_MIN_VALUE
Double.MIN_VALUE as BigDecimal. |
protected static java.math.BigInteger |
BIGI_LONG_MAX_VALUE
Long.MAX_VALUE as BigInteger. |
protected static java.math.BigInteger |
BIGI_LONG_MIN_VALUE
Long.MIN_VALUE as BigInteger. |
Constructor Summary | |
---|---|
JexlArithmetic(boolean lenient)
Creates a JexlArithmetic. |
Method Summary | |
---|---|
java.lang.Object |
add(java.lang.Object left,
java.lang.Object right)
Add two values together. |
protected java.lang.Object |
controlNullNullOperands()
The result of +,/,-,*,% when both operands are null. |
protected void |
controlNullOperand()
Throw a NPE if arithmetic is strict. |
java.lang.Object |
divide(java.lang.Object left,
java.lang.Object right)
Divide the left value by the right. |
boolean |
equals(java.lang.Object left,
java.lang.Object right)
Test if left and right are equal. |
boolean |
greaterThan(java.lang.Object left,
java.lang.Object right)
Test if left > right. |
boolean |
greaterThanOrEqual(java.lang.Object left,
java.lang.Object right)
Test if left >= right. |
protected boolean |
isFloatingPoint(java.lang.Object o)
Is Object a floating point number. |
protected boolean |
isFloatingPointNumber(java.lang.Object val)
Test if the passed value is a floating point number, i.e. |
protected boolean |
isFloatingPointType(java.lang.Object left,
java.lang.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(java.lang.Object o)
Is Object a whole number. |
boolean |
lessThan(java.lang.Object left,
java.lang.Object right)
Test if left < right. |
boolean |
lessThanOrEqual(java.lang.Object left,
java.lang.Object right)
Test if left <= right. |
boolean |
matches(java.lang.Object left,
java.lang.Object right)
Test if left regexp matches right. |
java.lang.Object |
mod(java.lang.Object left,
java.lang.Object right)
left value mod right. |
java.lang.Object |
multiply(java.lang.Object left,
java.lang.Object right)
Multiply the left value by the right. |
java.lang.Number |
narrow(java.lang.Number original)
Given a Number, return back the value using the smallest type the result will fit into. |
protected boolean |
narrowArguments(java.lang.Object[] args)
Replace all numbers in an arguments array with the smallest type that will fit. |
protected java.lang.Object |
narrowArrayType(java.lang.Object[] untyped)
Given an array of objects, attempt to type it more strictly. |
protected java.lang.Number |
narrowBigInteger(java.lang.Object lhs,
java.lang.Object rhs,
java.math.BigInteger bigi)
Given a BigInteger, narrow it to an Integer or Long if it fits and the arguments class allow it. |
java.lang.Object |
subtract(java.lang.Object left,
java.lang.Object right)
Subtract the right value from the left. |
java.math.BigDecimal |
toBigDecimal(java.lang.Object val)
Get a BigDecimal from the object passed. |
java.math.BigInteger |
toBigInteger(java.lang.Object val)
Get a BigInteger from the object passed. |
boolean |
toBoolean(java.lang.Object val)
Coerce to a boolean (not a java.lang.Boolean). |
double |
toDouble(java.lang.Object val)
Coerce to a double. |
int |
toInteger(java.lang.Object val)
Coerce to a int. |
long |
toLong(java.lang.Object val)
Coerce to a long (not a java.lang.Long). |
java.lang.String |
toString(java.lang.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 java.math.BigDecimal BIGD_DOUBLE_MAX_VALUE
protected static final java.math.BigDecimal BIGD_DOUBLE_MIN_VALUE
protected static final java.math.BigInteger BIGI_LONG_MAX_VALUE
protected static final java.math.BigInteger BIGI_LONG_MIN_VALUE
Constructor Detail |
---|
public JexlArithmetic(boolean lenient)
lenient
- whether this arithmetic is lenient or strictMethod Detail |
---|
public boolean isLenient()
protected java.lang.Object controlNullNullOperands()
java.lang.NullPointerException
- if strictprotected void controlNullOperand()
java.lang.NullPointerException
- if strictprotected boolean isFloatingPointType(java.lang.Object left, java.lang.Object right)
left
- one object to testright
- the other
protected boolean isFloatingPointNumber(java.lang.Object val)
val
- the object to be tested
protected boolean isFloatingPoint(java.lang.Object o)
o
- Object to be analyzed.
protected boolean isNumberable(java.lang.Object o)
o
- Object to be analyzed.
protected java.lang.Number narrowBigInteger(java.lang.Object lhs, java.lang.Object rhs, java.math.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 java.lang.Object narrowArrayType(java.lang.Object[] untyped)
untyped
- an untyped array
protected boolean narrowArguments(java.lang.Object[] args)
args
- the argument array
public java.lang.Object add(java.lang.Object left, java.lang.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 java.lang.Object divide(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
java.lang.ArithmeticException
- if right == 0public java.lang.Object mod(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
java.lang.ArithmeticException
- if right == 0.0public java.lang.Object multiply(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public java.lang.Object subtract(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public boolean matches(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public boolean equals(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public boolean lessThan(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public boolean greaterThan(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public boolean lessThanOrEqual(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public boolean greaterThanOrEqual(java.lang.Object left, java.lang.Object right)
left
- first valueright
- second value
public boolean toBoolean(java.lang.Object val)
val
- Object to be coerced.
public int toInteger(java.lang.Object val)
val
- Object to be coerced.
public long toLong(java.lang.Object val)
val
- Object to be coerced.
public java.math.BigInteger toBigInteger(java.lang.Object val)
val
- the object to be coerced.
java.lang.NullPointerException
- if val is null and mode is strict.public java.math.BigDecimal toBigDecimal(java.lang.Object val)
val
- the object to be coerced.
java.lang.NullPointerException
- if val is null and mode is strict.public double toDouble(java.lang.Object val)
val
- Object to be coerced.
java.lang.NullPointerException
- if val is null and mode is strict.public java.lang.String toString(java.lang.Object val)
val
- Object to be coerced.
java.lang.NullPointerException
- if val is null and mode is strict.public java.lang.Number narrow(java.lang.Number original)
original
- the original number.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |