public final class Objects extends Object
Modifier and Type | Method and Description |
---|---|
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 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 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 <T> T |
convertValue(Object value,
Class<T> toType)
Convert between basic Java types, i.e.
|
static <T> T |
defaultIfNull(T originalObj,
T defaultObj)
Returns the original object if this one is != null.
|
static double |
doubleValue(Object value)
Evaluates the given object as a double-precision floating-point number.
|
static boolean |
equal(Object a,
Object b)
Returns true if a and b are equal.
|
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 int |
hashCode(Object... obj)
returns hashcode of the objects by calling obj.hashcode().
|
static boolean |
isEqual(Object object1,
Object object2)
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 the
equals() sense. |
static long |
longValue(Object value)
Evaluates the given object as a long integer.
|
static Number |
newInteger(int type,
long value)
Returns a new Number object of an appropriate type to hold the given integer value.
|
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.
|
public static 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 static 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 static boolean booleanValue(Object value)
value
- an object to interpret as a booleanpublic static int compareWithConversion(Object v1, Object v2)
v1
- First value to comparev2
- second value to compareIllegalArgumentException
- if the objects are both non-numeric yet of incompatible types or do not implement
Comparable.public static <T> T convertValue(Object value, Class<T> toType)
This method also detects when arrays are being converted and converts the components of one array to the type of the other.
T
- target typevalue
- an object to be converted to the given typetoType
- class type to be converted topublic static 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 static boolean equal(Object a, Object b)
a
- Object ab
- Object bpublic static int getNumericType(int t1, int t2, boolean canBeNonNumeric)
t1
- type of one argument to an operatort2
- type of the other argumentcanBeNonNumeric
- whether the operator can be interpreted as non-numericpublic static int getNumericType(Object value)
value
- an object that needs to be interpreted as a numberpublic static int getNumericType(Object v1, Object v2)
v1
- one argument to a numeric operatorv2
- the other argumentpublic static int getNumericType(Object v1, Object v2, boolean canBeNonNumeric)
v1
- one argument to an operatorv2
- the other argumentcanBeNonNumeric
- whether the operator can be interpreted as non-numericpublic static boolean isEqual(Object object1, Object object2)
equals()
sense.object1
- First object to compareobject2
- Second object to comparepublic static 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 static Number newInteger(int type, long value)
type
- the nominal numeric type of the result, a constant from the NumericTypes interfacevalue
- the integer value to convert to a Number objectpublic static String stringValue(Object value)
value
- an object to interpret as a Stringpublic static int hashCode(Object... obj)
obj
- public static String stringValue(Object value, boolean trim)
value
- an object to interpret as a Stringtrim
- whether to trim the stringpublic static <T> T defaultIfNull(T originalObj, T defaultObj)
originalObj
- the original objectdefaultObj
- the default objectCopyright © 2006–2021 Apache Software Foundation. All rights reserved.