|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.omnaest.utils.structure.element.ObjectUtils
public class ObjectUtils
Helper which offers methods allowing to deal with arbitrary Objects
| Nested Class Summary | |
|---|---|
protected static class |
ObjectUtils.PrimitiveTypeArrayAnalysisResult
Result of the analysis for primitive arrays |
| Constructor Summary | |
|---|---|
ObjectUtils()
|
|
| Method Summary | ||
|---|---|---|
static
|
castArrayTo(Class<C> wrapperType,
Class<?> elementType,
Object array)
Casts a given Array to a wrapper Class type and its elements to the element Class type using
castTo(Class, Object). |
|
static
|
castArrayToMap(Class<? extends C> mapType,
Class<?> keyType,
Class<?> valueType,
Object array)
Casts a given Array to a Map class. |
|
static
|
castTo(Class<C> type,
Object object)
Casts a given Object to a given Class type. |
|
static
|
defaultIfNull(O object,
Factory<O> defaultObjectFactory)
Returns the object parameter if it is not null, otherwise the object created by the given Factory . |
|
static
|
defaultIfNull(O object,
O defaultObject)
Similar to defaultIfNull(Object, Object, Object...) |
|
static
|
defaultIfNull(O object,
O defaultObject,
O... defaultObjects)
Returns the object parameter if it is not null, otherwise the defaultObject. |
|
static boolean |
isAnyTypeAssignableFromInstance(Iterable<Class<?>> targetTypes,
Object object)
Returns true if the given object instance is assignable to at least one of the given types. |
|
static boolean |
isAnyTypeAssignableFromType(Iterable<Class<?>> targetTypes,
Class<?> sourceType)
Returns true if the given source type instance is assignable to at least one of the given target types. |
|
static boolean |
isArray(Object object)
Returns true if the given Object is not null and an Array type. |
|
static boolean |
isAssignableFromInstance(Class<?> targetType,
Object object)
Returns true if the given target Class is Class.isAssignableFrom(Class) from the given Object. |
|
static boolean |
isCollection(Object object)
Returns true if the given Object is not null and a Collection derived type |
|
static boolean |
isIterable(Object object)
Returns true if the given Object is not null and a Iterable derived type |
|
static boolean |
isList(Object object)
Returns true if the given Object is not null and a List derived type |
|
static boolean |
isMap(Object object)
Returns true if the given Object is not null and a Map derived type |
|
static boolean |
isPrimitiveOrPrimitiveWrapperType(Class<?> type)
Returns true if isPrimitiveType(Class) or isPrimitiveWrapperType(Class) returns true |
|
static boolean |
isPrimitiveType(Class<?> type)
Returns true if type is not null and Class.isPrimitive() is true for the given type |
|
static boolean |
isPrimitiveWrapperType(Class<?> type)
Returns true if the given Class type is a wrapper type of a primitive. |
|
static boolean |
isSortedMap(Object object)
Returns true if the given Object is not null and a SortedMap derived type |
|
static boolean |
isSortedSet(Object object)
Returns true if the given Object is not null and a SortedSet derived type |
|
static boolean |
isString(Object object)
isString( null ) = false isString( "" ) = true isString( "xyz" ) = true isString( 123 ) = false |
|
static Class<?> |
objectTypeFor(Class<?> type)
Returns the Object type for the given type. |
|
static Class<?> |
primitiveWrapperTypeFor(Class<?> primitiveType)
Returns the auto boxing type for a primitive Class type. |
|
static String |
toStringAsNestedHierarchy(Object object)
Generates a hierarchy representation of the object graph for the given Object. |
|
static String |
toStringAsSimpleNestedHierarchy(Object object)
Similar to toStringAsNestedHierarchy(Object) but with reduced information |
|
static ObjectTreeNavigator |
treeNavigator(Object object)
Returns a ObjectTreeNavigator for the given Object |
|
static Class<?> |
typeOf(Object instance)
Returns the Class of the given instance or null if null is given as instance |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ObjectUtils()
| Method Detail |
|---|
public static <C> C castArrayToMap(Class<? extends C> mapType,
Class<?> keyType,
Class<?> valueType,
Object array)
Array to a Map class. This is done by toggling between key and value for every index position
of the given array.
mapType - keyType - valueType - array -
public static <C> C castArrayTo(Class<C> wrapperType,
Class<?> elementType,
Object array)
Array to a wrapper Class type and its elements to the element Class type using
castTo(Class, Object).
wrapperType - elementType - array -
public static <C> C castTo(Class<C> type,
Object object)
Object to a given Class type. If the given type is a primitive the valueOf(...) method is used.
type - object -
public static boolean isPrimitiveWrapperType(Class<?> type)
Class type is a wrapper type of a primitive.
type -
public static boolean isPrimitiveType(Class<?> type)
Class.isPrimitive() is true for the given type
type -
public static boolean isPrimitiveOrPrimitiveWrapperType(Class<?> type)
isPrimitiveType(Class) or isPrimitiveWrapperType(Class) returns true
type -
public static boolean isString(Object object)
isString( null ) = false isString( "" ) = true isString( "xyz" ) = true isString( 123 ) = false
object -
public static boolean isMap(Object object)
Object is not null and a Map derived type
object -
public static boolean isSortedMap(Object object)
Object is not null and a SortedMap derived type
object -
public static boolean isSortedSet(Object object)
Object is not null and a SortedSet derived type
object -
public static boolean isList(Object object)
Object is not null and a List derived type
object -
public static boolean isCollection(Object object)
Object is not null and a Collection derived type
object -
public static boolean isIterable(Object object)
Object is not null and a Iterable derived type
object -
public static boolean isAssignableFromInstance(Class<?> targetType,
Object object)
Class is Class.isAssignableFrom(Class) from the given Object. In
other words is the assignment "TargetType target = (TargetType) object;" valid
targetType - object -
public static boolean isAnyTypeAssignableFromType(Iterable<Class<?>> targetTypes,
Class<?> sourceType)
targetTypes - sourceType -
public static boolean isAnyTypeAssignableFromInstance(Iterable<Class<?>> targetTypes,
Object object)
targetTypes - object -
public static boolean isArray(Object object)
Object is not null and an Array type.
object -
Class.isArray()public static Class<?> objectTypeFor(Class<?> type)
Object type for the given type. objectTypeFor(null) = null objectTypeFor(double) = Double objectTypeFor(String) = String objectTypeFor(Object) = Object
type -
primitiveWrapperTypeFor(Class),
isPrimitiveOrPrimitiveWrapperType(Class)public static Class<?> primitiveWrapperTypeFor(Class<?> primitiveType)
Class type. wrapperTypeForPrimitiveType( null ) = null wrapperTypeForPrimitiveType( boolean ) = Boolean wrapperTypeForPrimitiveType( double ) = Double wrapperTypeForPrimitiveType( primitiveType ) = wrapperType wrapperTypeForPrimitiveType( Double ) = Double wrapperTypeForPrimitiveType( wrapperType ) = wrapperType wrapperTypeForPrimitiveType( String ) = null
primitiveType -
objectTypeFor(Class)
public static <O> O defaultIfNull(O object,
O defaultObject)
defaultIfNull(Object, Object, Object...)
object - defaultObject -
public static <O> O defaultIfNull(O object,
O defaultObject,
O... defaultObjects)
ObjectUtils.defaultObject( x, * ) = x; ObjectUtils.defaultObject( null, default ) = default; ObjectUtils.defaultObject( null, null, null, default ) = default; ObjectUtils.defaultObject( null, default, null, null ) = default; ObjectUtils.defaultObject( null, default1, null, default2 ) = default1; ObjectUtils.defaultObject( null, null ) = null;
object - defaultObject - defaultObjects -
public static <O> O defaultIfNull(O object,
Factory<O> defaultObjectFactory)
Factory . ObjectUtils.defaultObject( x, * ) = x; ObjectUtils.defaultObject( null, factory ) = factory.newInstance(); ObjectUtils.defaultObject( null, null ) = null;
object - defaultObjectFactory -
public static String toStringAsNestedHierarchy(Object object)
Object.
|--[ org.omnaest.utils.structure.hierarchy.tree.adapter.ObjectToTreeNodeAdapterTest$TestClass@5801319c ]
|--[ fieldDouble = 1.234 ]
|--[ fieldString = value1 ]
|--[ fieldString2 = value2 ]
|--[ testClassSub = org.omnaest.utils.structure.hierarchy.tree.adapter.ObjectToTreeNodeAdapterTest$TestClassSub@790bc49d ]
|--[ fieldString = value3 ]
object -
public static String toStringAsSimpleNestedHierarchy(Object object)
toStringAsNestedHierarchy(Object) but with reduced information
object -
public static ObjectTreeNavigator treeNavigator(Object object)
ObjectTreeNavigator for the given Object
object -
public static Class<?> typeOf(Object instance)
Class of the given instance or null if null is given as instance
instance -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||