Class ReflectionHelper
java.lang.Object
org.hibernate.validator.internal.util.ReflectionHelper
Some reflection utility methods. Where necessary calls will be performed as
PrivilegedAction
which is necessary
for situations where a security manager is in place.- Author:
- Hardy Ferentschik, Gunnar Morling, Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI, Guillaume Smet
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
Returns the corresponding auto-boxed type if given a primitive type.static Type
Returns the corresponding auto-boxed type if given a primitive type.static Class<?>
getClassFromType
(Type type) Converts the givenType
to aClass
.static Type
getCollectionElementType
(Type type) Determines the type of the elements of anIterable
, array or the value of aMap
.static Object
getIndexedValue
(Object value, int index) Tries to retrieve the indexed value from the specified object.static Object
getMappedValue
(Object value, Object key) Tries to retrieve the mapped value from the specified object.static Object
static Object
static boolean
isCollection
(Type type) Indicates whether the given type represents a collection of elements or not (i.e.static boolean
isIndexable
(Type type) Indicates if the type is considered indexable (ie is aList
, an array or aMap
).static boolean
isIterable
(Type type) static boolean
static boolean
static Type
static Class<?>
unBoxedType
(Class<?> type) Returns the primitive type for a boxed type.
-
Method Details
-
typeOf
- Parameters:
member
- TheMember
instance for which to retrieve the type.- Returns:
- Returns the
Type
of the givenField
orMethod
. - Throws:
IllegalArgumentException
- in casemember
is not aField
orMethod
.
-
getValue
-
getValue
-
isCollection
Indicates whether the given type represents a collection of elements or not (i.e. whether it is anIterable
,Map
or array type). -
getCollectionElementType
Determines the type of the elements of anIterable
, array or the value of aMap
. -
isIndexable
Indicates if the type is considered indexable (ie is aList
, an array or aMap
).Note that it does not include
Set
s as they are not indexable.- Parameters:
type
- the type to inspect.- Returns:
- Returns true if the type is indexable.
-
getClassFromType
Converts the givenType
to aClass
.- Parameters:
type
- the type to convert- Returns:
- the class corresponding to the type
-
isIterable
- Parameters:
type
- the type to check.- Returns:
- Returns
true
iftype
is a iterable type,false
otherwise.
-
isMap
- Parameters:
type
- the type to check.- Returns:
- Returns
true
iftype
is implementingMap
,false
otherwise.
-
isList
- Parameters:
type
- the type to check.- Returns:
- Returns
true
iftype
is implementingList
,false
otherwise.
-
getIndexedValue
Tries to retrieve the indexed value from the specified object.- Parameters:
value
- The object from which to retrieve the indexed value. The object has to be nonnull
and either a collection or array.index
- The index.- Returns:
- The indexed value or
null
ifvalue
isnull
or not a collection or array.null
is also returned in case the index does not exist.
-
getMappedValue
Tries to retrieve the mapped value from the specified object.- Parameters:
value
- The object from which to retrieve the mapped value. The object has to be nonnull
and must implement the @{code Map} interface.key
- The map key. index.- Returns:
- The mapped value or
null
ifvalue
isnull
or not implementing @{code Map}.
-
boxedType
Returns the corresponding auto-boxed type if given a primitive type. Returns the given type itself otherwise. -
boxedType
Returns the corresponding auto-boxed type if given a primitive type. Returns the given type itself otherwise. -
unBoxedType
Returns the primitive type for a boxed type.- Parameters:
type
- the boxed type- Returns:
- the primitive type for a auto-boxed type. In case
Void
is passed (which is considered as primitive type byClass.isPrimitive()
),Void
will be returned. - Throws:
IllegalArgumentException
- in case the parameterprimitiveType
does not represent a primitive type.
-