| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
| 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 int | 
BIGD_SCALE
Default BigDecimal scale.  | 
protected static BigInteger | 
BIGI_LONG_MAX_VALUE
Long.MAX_VALUE as BigInteger.  | 
protected static BigInteger | 
BIGI_LONG_MIN_VALUE
Long.MIN_VALUE as BigInteger.  | 
protected  MathContext | 
mathContext
The big decimal math context.  | 
protected  int | 
mathScale
The big decimal scale.  | 
| Constructor Summary | |
|---|---|
JexlArithmetic(boolean lenient)
Creates a JexlArithmetic.  | 
|
JexlArithmetic(boolean lenient,
                             MathContext bigdContext,
                             int bigdScale)
Creates a JexlArithmetic.  | 
|
| Method Summary | |
|---|---|
 Object | 
add(Object left,
       Object right)
Add two values together.  | 
 Object | 
bitwiseAnd(Object left,
                     Object right)
Performs a bitwise and.  | 
 Object | 
bitwiseComplement(Object val)
Performs a bitwise complement.  | 
 Object | 
bitwiseOr(Object left,
                   Object right)
Performs a bitwise or.  | 
 Object | 
bitwiseXor(Object left,
                     Object right)
Performs a bitwise xor.  | 
protected  int | 
compare(Object left,
               Object right,
               String operator)
Performs a comparison.  | 
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.  | 
 MathContext | 
getMathContext()
The MathContext instance used for +,-,/,*,% operations on big decimals.  | 
 int | 
getMathScale()
The BigDecimal scale used for comparison and coercion operations.  | 
 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 | 
narrowAccept(Class<?> narrow,
                         Class<?> source)
Whether we consider the narrow class as a potential candidate for narrowing the source.  | 
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 | 
narrowBigDecimal(Object lhs,
                                 Object rhs,
                                 BigDecimal bigd)
Given a BigDecimal, attempt to narrow it to an Integer or Long if it fits if one of the arguments is a numberable.  | 
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.  | 
protected  Number | 
narrowNumber(Number original,
                         Class<?> narrow)
Given a Number, return back the value attempting to narrow it to a target class.  | 
 Object | 
negate(Object val)
Negates a value (unary minus for numbers).  | 
 BigDecimal | 
roundBigDecimal(BigDecimal number)
Ensure a big decimal is rounded by this arithmetic scale and rounding mode.  | 
 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
protected static final int BIGD_SCALE
protected final MathContext mathContext
protected final int mathScale
| Constructor Detail | 
|---|
public JexlArithmetic(boolean lenient)
lenient - whether this arithmetic is lenient or strictpublic JexlArithmetic(boolean lenient,
                      MathContext bigdContext,
                      int bigdScale)
lenient - whether this arithmetic is lenient or strictbigdContext - the math context instance to use for +,-,/,*,% operations on big decimals.bigdScale - the scale used for big decimals.| Method Detail | 
|---|
public boolean isLenient()
public MathContext getMathContext()
public int getMathScale()
public BigDecimal roundBigDecimal(BigDecimal number)
number - the big decimal to round
protected Object controlNullNullOperands()
ArithmeticException - if strictprotected void controlNullOperand()
ArithmeticException - 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 Number narrowBigDecimal(Object lhs,
                                  Object rhs,
                                  BigDecimal bigd)
lhs - the left hand side operand that lead to the bigd resultrhs - the right hand side operand that lead to the bigd resultbigd - the BigDecimal 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 Object negate(Object val)
val - the value to negate
public boolean matches(Object left,
                       Object right)
left - first valueright - second value
public Object bitwiseAnd(Object left,
                         Object right)
left - the left operandright - the right operator
public Object bitwiseOr(Object left,
                        Object right)
left - the left operandright - the right operator
public Object bitwiseXor(Object left,
                         Object right)
left - the left operandright - the right operator
public Object bitwiseComplement(Object val)
val - the operand
protected int compare(Object left,
                      Object right,
                      String operator)
left - the left operandright - the right operatoroperator - the operator
ArithmeticException - if either left or right is nullpublic 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.
protected boolean narrowAccept(Class<?> narrow,
                               Class<?> source)
narrow - the target narrow classsource - the orginal source class
protected Number narrowNumber(Number original,
                              Class<?> narrow)
original - the original numbernarrow - the attempted target class
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||