Top Description Fields Constructors Methods
org.hibernate.validator.internal.util

public final Class ReflectionHelper

extends Object
Class Inheritance
Static Imports
org.hibernate.validator.internal.util.CollectionHelper.newHashMap

Some reflection utility methods. Where necessary calls will be performed as PrivilegedAction which is necessary for situations where a security manager is in place.
Authors
Hardy Ferentschik, Gunnar Morling, Kevin Pollet <[email protected]> (C) 2011 SERLI, Guillaume Smet

Field Summary

Modifier and TypeField and Description
private static final Log
private static final Map<Class<?>, Class<?>>
private static final Map<Class<?>, Class<?>>

Constructor Summary

AccessConstructor and Description
private
ReflectionHelper()

Private constructor in order to avoid instantiation.

Method Summary

Modifier and TypeMethod and Description
public static Type
boxedType(Type type)

Returns the corresponding auto-boxed type if given a primitive type.

public static Class<?>
boxedType(Class<?> type)

Returns the corresponding auto-boxed type if given a primitive type.

public static Class<?>

Returns:

the class corresponding to the type
getClassFromType
(Type
the type to convert
type
)

Converts the given Type to a Class.

public static Type
getCollectionElementType(Type type)

Determines the type of the elements of an Iterable, array or the value of a Map.

public static Object

Returns:

The indexed value or null if value is null or not a collection or array. null is also returned in case the index does not exist.
getIndexedValue
(Object
The object from which to retrieve the indexed value. The object has to be non null and either a collection or array.
value
,
int
The index.
index
)

Tries to retrieve the indexed value from the specified object.

public static Object

Returns:

The mapped value or null if value is null or not implementing @{code Map}.
getMappedValue
(Object
The object from which to retrieve the mapped value. The object has to be non null and must implement the @{code Map} interface.
value
,
Object
The map key. index.
key
)

Tries to retrieve the mapped value from the specified object.

public static Object
getValue(Field field, Object object)

public static Object
getValue(Method method, Object object)

private static Class<?>

Returns:

the auto-boxed type of a primitive type. In case Void is passed (which is considered as primitive type by Class#isPrimitive()), Void will be returned.
internalBoxedType
(Class<?>
the primitive type
primitiveType
)

Returns the auto-boxed type of a primitive type.

public static boolean
isCollection(Type type)

Indicates whether the given type represents a collection of elements or not (i.e. whether it is an Iterable, Map or array type).

public static boolean

Returns:

Returns true if the type is indexable.
isIndexable
(Type
the type to inspect.
type
)

Indicates if the type is considered indexable (ie is a List, an array or a Map).

public static boolean

Returns:

Returns true if type is a iterable type, false otherwise.
isIterable
(Type
the type to check.
type
)

public static boolean

Returns:

Returns true if type is implementing List, false otherwise.
isList
(Type
the type to check.
type
)

public static boolean

Returns:

Returns true if type is implementing Map, false otherwise.
isMap
(Type
the type to check.
type
)

public static Type

Returns:

Returns the Type of the given Field or Method.
typeOf
(Member
The Member instance for which to retrieve the type.
member
)

public static Class<?>

Returns:

the primitive type for a auto-boxed type. In case Void is passed (which is considered as primitive type by Class#isPrimitive()), Void will be returned.
unBoxedType
(Class<?>
the boxed type
type
)

Returns the primitive type for a boxed type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Log LOG
PRIMITIVE_TO_WRAPPER_TYPESback to summary
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPES
WRAPPER_TO_PRIMITIVE_TYPESback to summary
private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPES

Constructor Detail

ReflectionHelperback to summary
private ReflectionHelper()

Private constructor in order to avoid instantiation.

Method Detail

boxedTypeback to summary
public static Type boxedType(Type type)

Returns the corresponding auto-boxed type if given a primitive type. Returns the given type itself otherwise.

boxedTypeback to summary
public static Class<?> boxedType(Class<?> type)

Returns the corresponding auto-boxed type if given a primitive type. Returns the given type itself otherwise.

getClassFromTypeback to summary
public static Class<?> getClassFromType(Type type)

Converts the given Type to a Class.

Parameters
type:Type

the type to convert

Returns:Class<?>

the class corresponding to the type

getCollectionElementTypeback to summary
public static Type getCollectionElementType(Type type)

Determines the type of the elements of an Iterable, array or the value of a Map.

getIndexedValueback to summary
public static Object getIndexedValue(Object value, int index)

Tries to retrieve the indexed value from the specified object.

Parameters
value:Object

The object from which to retrieve the indexed value. The object has to be non null and either a collection or array.

index:int

The index.

Returns:Object

The indexed value or null if value is null or not a collection or array. null is also returned in case the index does not exist.

getMappedValueback to summary
public static Object getMappedValue(Object value, Object key)

Tries to retrieve the mapped value from the specified object.

Parameters
value:Object

The object from which to retrieve the mapped value. The object has to be non null and must implement the @{code Map} interface.

key:Object

The map key. index.

Returns:Object

The mapped value or null if value is null or not implementing @{code Map}.

getValueback to summary
public static Object getValue(Field field, Object object)
getValueback to summary
public static Object getValue(Method method, Object object)
internalBoxedTypeback to summary
private static Class<?> internalBoxedType(Class<?> primitiveType)

Returns the auto-boxed type of a primitive type.

Parameters
primitiveType:Class<?>

the primitive type

Returns:Class<?>

the auto-boxed type of a primitive type. In case Void is passed (which is considered as primitive type by Class#isPrimitive()), Void will be returned.

Exceptions
IllegalArgumentException:
in case the parameter primitiveType does not represent a primitive type.
isCollectionback to summary
public static boolean isCollection(Type type)

Indicates whether the given type represents a collection of elements or not (i.e. whether it is an Iterable, Map or array type).

isIndexableback to summary
public static boolean isIndexable(Type type)

Indicates if the type is considered indexable (ie is a List, an array or a Map).

Note that it does not include Sets as they are not indexable.

Parameters
type:Type

the type to inspect.

Returns:boolean

Returns true if the type is indexable.

isIterableback to summary
public static boolean isIterable(Type type)
Parameters
type:Type

the type to check.

Returns:boolean

Returns true if type is a iterable type, false otherwise.

isListback to summary
public static boolean isList(Type type)
Parameters
type:Type

the type to check.

Returns:boolean

Returns true if type is implementing List, false otherwise.

isMapback to summary
public static boolean isMap(Type type)
Parameters
type:Type

the type to check.

Returns:boolean

Returns true if type is implementing Map, false otherwise.

typeOfback to summary
public static Type typeOf(Member member)
Parameters
member:Member

The Member instance for which to retrieve the type.

Returns:Type

Returns the Type of the given Field or Method.

Exceptions
IllegalArgumentException:
in case member is not a Field or Method.
unBoxedTypeback to summary
public static Class<?> unBoxedType(Class<?> type)

Returns the primitive type for a boxed type.

Parameters
type:Class<?>

the boxed type

Returns:Class<?>

the primitive type for a auto-boxed type. In case Void is passed (which is considered as primitive type by Class#isPrimitive()), Void will be returned.

Exceptions
IllegalArgumentException:
in case the parameter primitiveType does not represent a primitive type.