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 TypeReturns the corresponding auto-boxed type if given a primitive type.static Class<?>getClassFromType(Type type) Converts the givenTypeto aClass.static TypegetCollectionElementType(Type type) Determines the type of the elements of anIterable, array or the value of aMap.static ObjectgetIndexedValue(Object value, int index) Tries to retrieve the indexed value from the specified object.static ObjectgetMappedValue(Object value, Object key) Tries to retrieve the mapped value from the specified object.static Objectstatic Objectstatic booleanisCollection(Type type) Indicates whether the given type represents a collection of elements or not (i.e.static booleanisIndexable(Type type) Indicates if the type is considered indexable (ie is aList, an array or aMap).static booleanisIterable(Type type) static booleanstatic booleanstatic Typestatic Class<?>unBoxedType(Class<?> type) Returns the primitive type for a boxed type.
-
Method Details
-
typeOf
- Parameters:
member- TheMemberinstance for which to retrieve the type.- Returns:
- Returns the
Typeof the givenFieldorMethod. - Throws:
IllegalArgumentException- in casememberis not aFieldorMethod.
-
getValue
-
getValue
-
isCollection
Indicates whether the given type represents a collection of elements or not (i.e. whether it is anIterable,Mapor 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
Sets as they are not indexable.- Parameters:
type- the type to inspect.- Returns:
- Returns true if the type is indexable.
-
getClassFromType
Converts the givenTypeto aClass.- Parameters:
type- the type to convert- Returns:
- the class corresponding to the type
-
isIterable
- Parameters:
type- the type to check.- Returns:
- Returns
trueiftypeis a iterable type,falseotherwise.
-
isMap
- Parameters:
type- the type to check.- Returns:
- Returns
trueiftypeis implementingMap,falseotherwise.
-
isList
- Parameters:
type- the type to check.- Returns:
- Returns
trueiftypeis implementingList,falseotherwise.
-
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 nonnulland either a collection or array.index- The index.- Returns:
- The indexed value or
nullifvalueisnullor not a collection or array.nullis 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 nonnulland must implement the @{code Map} interface.key- The map key. index.- Returns:
- The mapped value or
nullifvalueisnullor 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
Voidis passed (which is considered as primitive type byClass.isPrimitive()),Voidwill be returned. - Throws:
IllegalArgumentException- in case the parameterprimitiveTypedoes not represent a primitive type.
-