Package ognl
Class OgnlOps
java.lang.Object
ognl.OgnlOps
- All Implemented Interfaces:
NumericTypes
This is an abstract class with static methods that define the operations of OGNL.
- Author:
- Luke Blanshard (blanshlu@netscape.net), Drew Davidson (drew@ognl.org)
-
Field Summary
Fields inherited from interface ognl.NumericTypes
BIGDEC, BIGINT, BOOL, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, MIN_REAL_TYPE, NONNUMERIC, SHORT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
static BigDecimal
bigDecValue
(Object value) Evaluates the given object as a BigDecimal.static BigInteger
bigIntValue
(Object value) Evaluates the given object as a BigInteger.static Object
static Object
static Object
static Object
static boolean
booleanValue
(boolean value) static boolean
booleanValue
(double value) static boolean
booleanValue
(float value) static boolean
booleanValue
(int value) static boolean
booleanValue
(long value) static boolean
booleanValue
(Object value) Evaluates the given object as a boolean: if it is a Boolean object, it's easy; if it's a Number or a Character, returns true for non-zero objects; and otherwise returns true for non-null objects.static RuntimeException
Utility method that converts incoming exceptions toRuntimeException
instances - or casts them if they already are.static int
compareWithConversion
(Object v1, Object v2) Compares two objects for equality, even if it has to convert one of them to the other type.static Object
convertValue
(boolean value, Class toType) static Object
convertValue
(boolean value, Class toType, boolean preventNull) static Object
convertValue
(byte value, Class toType) static Object
convertValue
(byte value, Class toType, boolean preventNull) static Object
convertValue
(char value, Class toType) static Object
convertValue
(char value, Class toType, boolean preventNull) static Object
convertValue
(double value, Class toType) static Object
convertValue
(double value, Class toType, boolean preventNull) static Object
convertValue
(float value, Class toType) static Object
convertValue
(float value, Class toType, boolean preventNull) static Object
convertValue
(int value, Class toType) static Object
convertValue
(int value, Class toType, boolean preventNull) static Object
convertValue
(long value, Class toType) static Object
convertValue
(long value, Class toType, boolean preventNull) static Object
convertValue
(Object value, Class toType) Returns the value converted numerically to the given class type This method also detects when arrays are being converted and converts the components of one array to the type of the other.static Object
convertValue
(Object value, Class toType, boolean preventNulls) static Object
static double
doubleValue
(Object value) Evaluates the given object as a double-precision floating-point number.static boolean
static String
getEscapedChar
(char ch) static String
getEscapeString
(String value) static int
getIntValue
(Object value) Converts the specified value to a primitive integer value.static int
getNumericType
(int t1, int t2, boolean canBeNonNumeric) Returns the constant from the NumericTypes interface that best expresses the type of an operation, which can be either numeric or not, on the two given types.static int
getNumericType
(Object value) Returns a constant from the NumericTypes interface that represents the numeric type of the given object.static int
getNumericType
(Object v1, Object v2) Returns the constant from the NumericTypes interface that best expresses the type of a numeric operation on the two given objects.static int
getNumericType
(Object v1, Object v2, boolean canBeNonNumeric) Returns the constant from the NumericTypes interface that best expresses the type of an operation, which can be either numeric or not, on the two given objects.static boolean
static boolean
static boolean
Returns true if object1 is equal to object2 in either the sense that they are the same object or, if both are non-null if they are equal in theequals()
sense.static boolean
static long
Evaluates the given object as a long integer.static Object
static Object
static Number
newInteger
(int type, long value) Returns a new Number object of an appropriate type to hold the given integer value.static Number
newReal
(int type, double value) Returns a new Number object of an appropriate type to hold the given real value.static Object
static Object
returnValue
(Object ignore, Object returnValue) static Object
static Object
shiftRight
(Object v1, Object v2) static String
stringValue
(Object value) Evaluates the given object as a String.static String
stringValue
(Object value, boolean trim) Evaluates the given object as a String and trims it if the trim flag is true.static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
static Object
unsignedShiftRight
(Object v1, Object v2)
-
Constructor Details
-
OgnlOps
public OgnlOps()
-
-
Method Details
-
compareWithConversion
Compares two objects for equality, even if it has to convert one of them to the other type. If both objects are numeric they are converted to the widest type and compared. If one is non-numeric and one is numeric the non-numeric is converted to double and compared to the double numeric value. If both are non-numeric and Comparable and the types are compatible (i.e. v1 is of the same or superclass of v2's type) they are compared with Comparable.compareTo(). If both values are non-numeric and not Comparable or of incompatible classes this will throw and IllegalArgumentException.- Parameters:
v1
- First value to comparev2
- second value to compare- Returns:
- integer describing the comparison between the two objects. A negative number indicates that v1 < v2. Positive indicates that v1 > v2. Zero indicates v1 == v2.
- Throws:
IllegalArgumentException
- if the objects are both non-numeric yet of incompatible types or do not implement Comparable.
-
isEqual
Returns true if object1 is equal to object2 in either the sense that they are the same object or, if both are non-null if they are equal in theequals()
sense.- Parameters:
object1
- First object to compareobject2
- Second object to compare- Returns:
- true if v1 == v2
-
booleanValue
public static boolean booleanValue(boolean value) -
booleanValue
public static boolean booleanValue(int value) -
booleanValue
public static boolean booleanValue(float value) -
booleanValue
public static boolean booleanValue(long value) -
booleanValue
public static boolean booleanValue(double value) -
booleanValue
Evaluates the given object as a boolean: if it is a Boolean object, it's easy; if it's a Number or a Character, returns true for non-zero objects; and otherwise returns true for non-null objects.- Parameters:
value
- an object to interpret as a boolean- Returns:
- the boolean value implied by the given object
-
longValue
Evaluates the given object as a long integer.- Parameters:
value
- an object to interpret as a long integer- Returns:
- the long integer value implied by the given object
- Throws:
NumberFormatException
- if the given object can't be understood as a long integer
-
doubleValue
Evaluates the given object as a double-precision floating-point number.- Parameters:
value
- an object to interpret as a double- Returns:
- the double value implied by the given object
- Throws:
NumberFormatException
- if the given object can't be understood as a double
-
bigIntValue
Evaluates the given object as a BigInteger.- Parameters:
value
- an object to interpret as a BigInteger- Returns:
- the BigInteger value implied by the given object
- Throws:
NumberFormatException
- if the given object can't be understood as a BigInteger
-
bigDecValue
Evaluates the given object as a BigDecimal.- Parameters:
value
- an object to interpret as a BigDecimal- Returns:
- the BigDecimal value implied by the given object
- Throws:
NumberFormatException
- if the given object can't be understood as a BigDecimal
-
stringValue
Evaluates the given object as a String and trims it if the trim flag is true.- Parameters:
value
- an object to interpret as a String- Returns:
- the String value implied by the given object as returned by the toString() method, or "null" if the object is null.
-
stringValue
Evaluates the given object as a String.- Parameters:
value
- an object to interpret as a String- Returns:
- the String value implied by the given object as returned by the toString() method, or "null" if the object is null.
-
getNumericType
Returns a constant from the NumericTypes interface that represents the numeric type of the given object.- Parameters:
value
- an object that needs to be interpreted as a number- Returns:
- the appropriate constant from the NumericTypes interface
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
convertValue
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
convertValue
Returns the value converted numerically to the given class type This method also detects when arrays are being converted and converts the components of one array to the type of the other.- Parameters:
value
- an object to be converted to the given typetoType
- class type to be converted to- Returns:
- converted value of the type given, or value if the value cannot be converted to the given type.
-
toArray
-
toArray
-
convertValue
-
getIntValue
Converts the specified value to a primitive integer value.- Null values will cause a -1 to be returned.
Number
instances have their intValue() methods invoked.- All other types result in calling Integer.parseInt(value.toString());
- Parameters:
value
- The object to get the value of.- Returns:
- A valid integer.
-
getNumericType
Returns the constant from the NumericTypes interface that best expresses the type of a numeric operation on the two given objects.- Parameters:
v1
- one argument to a numeric operatorv2
- the other argument- Returns:
- the appropriate constant from the NumericTypes interface
-
getNumericType
public static int getNumericType(int t1, int t2, boolean canBeNonNumeric) Returns the constant from the NumericTypes interface that best expresses the type of an operation, which can be either numeric or not, on the two given types.- Parameters:
t1
- type of one argument to an operatort2
- type of the other argumentcanBeNonNumeric
- whether the operator can be interpreted as non-numeric- Returns:
- the appropriate constant from the NumericTypes interface
-
getNumericType
Returns the constant from the NumericTypes interface that best expresses the type of an operation, which can be either numeric or not, on the two given objects.- Parameters:
v1
- one argument to an operatorv2
- the other argumentcanBeNonNumeric
- whether the operator can be interpreted as non-numeric- Returns:
- the appropriate constant from the NumericTypes interface
-
newInteger
Returns a new Number object of an appropriate type to hold the given integer value. The type of the returned object is consistent with the given type argument, which is a constant from the NumericTypes interface.- Parameters:
type
- the nominal numeric type of the result, a constant from the NumericTypes interfacevalue
- the integer value to convert to a Number object- Returns:
- a Number object with the given value, of type implied by the type argument
-
newReal
Returns a new Number object of an appropriate type to hold the given real value. The type of the returned object is always either Float or Double, and is only Float if the given type tag (a constant from the NumericTypes interface) is FLOAT.- Parameters:
type
- the nominal numeric type of the result, a constant from the NumericTypes interfacevalue
- the real value to convert to a Number object- Returns:
- a Number object with the given value, of type implied by the type argument
-
binaryOr
-
binaryXor
-
binaryAnd
-
equal
-
less
-
greater
-
in
- Throws:
OgnlException
-
shiftLeft
-
shiftRight
-
unsignedShiftRight
-
add
-
subtract
-
multiply
-
divide
-
remainder
-
negate
-
bitNegate
-
getEscapeString
-
getEscapedChar
-
returnValue
-
castToRuntime
Utility method that converts incoming exceptions toRuntimeException
instances - or casts them if they already are.- Parameters:
t
- The exception to cast.- Returns:
- The exception cast to a
RuntimeException
.
-