public final class ObjectUtils extends Object
If the value isn't an instance of the specified type, then converts the value if possible.
The following conversions are valid:
| Convert to type | Valid input value types | Notes |
|---|---|---|
A class that is the normal type of a registered PojoSwap.
|
A value whose class matches the transformed type of that registered PojoSwap.
|
|
A class that is the transformed type of a registered PojoSwap.
|
A value whose class matches the normal type of that registered PojoSwap.
|
|
Number (e.g. Integer, Short, Float,...)
Number. (e.g. Integer.,
Short., Float.,...)
|
Number, String, |
For primitive TYPES, |
Map (e.g. Map, HashMap, TreeMap, ObjectMap)
|
Map
|
If Map is not constructible, a ObjectMap is created.
|
Collection (e.g. List, LinkedList, HashSet, ObjectList)
|
Collection<Object>
Object[]
|
If Collection is not constructible, a ObjectList is created.
|
X[] (array of any type X)
|
List<X>
|
|
X[][] (multi-dimensional arrays)
|
List<List<X>>
List<X[]>
List[]<X>
|
|
Enum
|
String
|
|
| Bean |
Map
|
|
String
|
Anything | Arrays are converted to JSON arrays |
Anything with one of the following methods:
|
String
|
|
| Constructor and Description |
|---|
ObjectUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
castOrNull(Object o,
Class<T> c)
If the specified object is an instance of the specified class, casts it to that type.
|
static boolean |
equals(Object o1,
Object o2)
Returns
|
static <T> T |
firstNonEmpty(T... o)
Returns the first non-empty value in the list of objects.
|
static <T> T |
firstNonNull(T... t)
Returns the first non-null value in the specified array
|
static int |
firstNonZero(int... ints)
Returns the first non-zero value in the list of ints.
|
static Enum<?>[] |
getEnumConstants(Class<?> c)
Returns the enum names for the specified enum class.
|
static boolean |
isEmpty(Object o)
Returns
|
static Boolean |
toBoolean(Object o)
Converts an object to a Boolean.
|
static Integer |
toInteger(Object o)
Converts an object to an Integer.
|
static <T> T |
toMemberType(Object outer,
Object value,
Class<T> type)
Converts the specified object to the specified type.
|
static Number |
toNumber(Object o)
Converts an object to a Number.
|
static <T> T |
toType(Object value,
Class<T> type)
Converts the specified object to the specified type.
|
static <T> T |
toType(Object value,
Class<T> type,
Type... args)
Converts the specified object to the specified type.
|
public ObjectUtils()
public static <T> T toType(Object value, Class<T> type)
T - The class type to convert the value to.value - The value to convert.type - The class type to convert the value to.InvalidDataConversionException - If the specified value cannot be converted to the specified type.public static <T> T toType(Object value, Class<T> type, Type... args)
T - The class type to convert the value to.value - The value to convert.type - The class type to convert the value to.args - The type arguments.InvalidDataConversionException - If the specified value cannot be converted to the specified type.public static <T> T toMemberType(Object outer, Object value, Class<T> type)
T - The class type to convert the value to.outer - If class is a member class, this is the instance of the containing class.
Should be value - The value to convert.type - The class type to convert the value to.InvalidDataConversionException - If the specified value cannot be converted to the specified type.public static boolean equals(Object o1, Object o2)
Gracefully handles
o1 - Object #1o2 - Object #2public static boolean isEmpty(Object o)
Return
Object.toString().
o - The object to test.@SafeVarargs public static <T> T firstNonNull(T... t)
t - public static Boolean toBoolean(Object o)
o - The object to convert.public static Integer toInteger(Object o)
o - The object to convert.public static Number toNumber(Object o)
o - The object to convert.public static Enum<?>[] getEnumConstants(Class<?> c)
c - The enum class.public static <T> T castOrNull(Object o, Class<T> c)
o - The object to cast.c - The class to cast to.public static int firstNonZero(int... ints)
ints - The ints to check.0 if they were all zero.@SafeVarargs public static <T> T firstNonEmpty(T... o)
o - The objects to check.isEmpty(Object) returns Copyright © 2018 Apache. All rights reserved.