public class ValueUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
protected Map<Class<?>,Object> |
defaultValues |
protected Map<Class<?>,ValueType> |
typeMap |
| Modifier | Constructor and Description |
|---|---|
protected |
ValueUtils() |
| Modifier and Type | Method and Description |
|---|---|
Object |
add(Object v1,
Object v2)
Adds the two objects given.
|
BigDecimal |
bigDecValue(Object value)
Evaluates the given object as a BigDecimal.
|
BigInteger |
bigIntValue(Object value)
Evaluates the given object as a BigInteger.
|
Boolean |
booleanValue(Object value) |
int |
compareWithConversion(Object v1,
Object v2) |
int |
compareWithConversion(Object v1,
Object v2,
Number epsilon) |
Object |
convertValue(Class<?> toType,
Object value,
Object defaultValue)
Returns the value converted numerically to the given class type.
|
Number |
createInteger(ValueType type,
long value)
Returns a new Number object of an appropriate type to hold the given
integer value.
|
Number |
createReal(ValueType type,
double value)
Returns a new Number object of an appropriate type to hold the given real
value.
|
Object |
divide(Object v1,
Object v2)
Divides the first argument by the second
|
double |
doubleValue(Object value)
Evaluates the given object as a double-precision floating-point number.
|
static ValueUtils |
getInstance() |
ValueType |
getNumericType(ValueType t1,
ValueType 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.
|
ValueType |
getType(Object value) |
long |
longValue(Object value)
Evaluates the given object as a long integer.
|
Object |
multiply(Object v1,
Object v2)
Multiplies v1 times v2.
|
Object |
negate(Object v1)
Negates v1.
|
Object |
remainder(Object v1,
Object v2)
Returns the number of the first argument, v1, divided by the second
number's remainder (modulus).
|
String |
stringValue(Object value,
boolean trim)
Evaluates the given object as a String and trims it if the trim flag is
true.
|
Object |
subtract(Object v1,
Object v2)
Subtracts v2 from v1.
|
public static ValueUtils getInstance()
public ValueType getNumericType(ValueType t1, ValueType t2, boolean canBeNonNumeric)
t1 - one argument type to an operatort2 - the other argument typecanBeNonNumeric - whether the operator can be interpreted as non-numericpublic String stringValue(Object value, boolean trim)
value - an object to interpret as a Stringtrim - if true this returned string value is trimmed of whitespace
using String.trim().public long longValue(Object value) throws NumberFormatException
value - an object to interpret as a long integerNumberFormatException - if the given object can't be understood as a long integerpublic double doubleValue(Object value) throws NumberFormatException
value - an object to interpret as a doubleNumberFormatException - if the given object can't be understood as a doublepublic BigDecimal bigDecValue(Object value) throws NumberFormatException
value - an object to interpret as a BigDecimalNumberFormatException - if the given object can't be understood as a BigDecimalpublic BigInteger bigIntValue(Object value) throws NumberFormatException
value - an object to interpret as a BigIntegerNumberFormatException - if the given object can't be understood as a BigIntegerpublic Object add(Object v1, Object v2)
v1 - First addendv2 - Second addendpublic Object subtract(Object v1, Object v2)
v1 - Value to be subtracted from.v2 - Value to be subtracted from v1.public Object negate(Object v1)
v1 - Value to be negated.public Object multiply(Object v1, Object v2)
v1 - First multiplicandv2 - Second multiplicandpublic Object divide(Object v1, Object v2)
v1 - Dividendv2 - Divisorpublic Object remainder(Object v1, Object v2)
v1 - Dividendv2 - Divisorpublic Number createInteger(ValueType type, long value)
type - the nominal numeric type of the resultvalue - the integer value to convert to a Number objectpublic Number createReal(ValueType type, double value)
type - the nominal numeric type of the resultvalue - the real value to convert to a Number objectpublic Object convertValue(Class<?> toType, Object value, Object defaultValue)
toType - class type to be converted tovalue - an object to be converted to the given typedefaultValue - value returned in the event that no conversion is possible to
the given typeCopyright © 2020 Fraunhofer IWU. All rights reserved.