Package com.aspectran.utils
Class TypeUtils
java.lang.Object
com.aspectran.utils.TypeUtils
Utility methods focusing on type inspection, particularly with regard to generics.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class
<?> getPrimitiveWrapper
(Class<?> primitiveType) Gets the wrapper object class for the given primitive type class.static boolean
isAssignable
(Class<?> lhsType, Class<?> rhsType) Check if the right-hand side type may be assigned to the left-hand side type, assuming setting by reflection.static boolean
isAssignableValue
(Class<?> type, Object value) Determine if the given type is assignable from the given value, assuming setting by reflection.static boolean
isPrimitiveArray
(Class<?> clazz) Check if the given class represents an array of primitives, i.e.static boolean
isPrimitiveWrapper
(Class<?> clazz) Check if the given class represents a primitive wrapper, i.e.static boolean
isPrimitiveWrapperArray
(Class<?> clazz) Check if the given class represents an array of primitive wrappers, i.e.static Class<?>[]
wrappersToPrimitives
(Class<?>[] classes) Converts the specified array of wrapper Class objects to an array of its corresponding primitive Class objects.static Class
<?> wrapperToPrimitive
(Class<?> cls) Converts the specified wrapper class to its corresponding primitive class.
-
Constructor Details
-
TypeUtils
public TypeUtils()
-
-
Method Details
-
isPrimitiveWrapper
Check if the given class represents a primitive wrapper, i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.- Parameters:
clazz
- the class to check- Returns:
- whether the given class is a primitive wrapper class
-
isPrimitiveArray
Check if the given class represents an array of primitives, i.e. boolean, byte, char, short, int, long, float, or double.- Parameters:
clazz
- the class to check- Returns:
- whether the given class is a primitive array class
-
isPrimitiveWrapperArray
Check if the given class represents an array of primitive wrappers, i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.- Parameters:
clazz
- the class to check- Returns:
- whether the given class is a primitive wrapper array class
-
isAssignable
Check if the right-hand side type may be assigned to the left-hand side type, assuming setting by reflection. Considers primitive wrapper classes as assignable to the corresponding primitive types.- Parameters:
lhsType
- the target typerhsType
- the value type that should be assigned to the target type- Returns:
- if the target type is assignable from the value type
-
isAssignableValue
Determine if the given type is assignable from the given value, assuming setting by reflection. Considers primitive wrapper classes as assignable to the corresponding primitive types.- Parameters:
type
- the target typevalue
- the value that should be assigned to the type- Returns:
- if the type is assignable from the value
-
getPrimitiveWrapper
Gets the wrapper object class for the given primitive type class. For example, passingboolean.class
returnsBoolean.class
- Parameters:
primitiveType
- the primitive type class for which a match is to be found- Returns:
- the wrapper type associated with the given primitive or null if no match is found
-
wrapperToPrimitive
Converts the specified wrapper class to its corresponding primitive class.
This method is the counter part of
primitiveToWrapper()
. If the passed in class is a wrapper class for a primitive type, this primitive type will be returned (e.g.Integer.TYPE
forInteger.class
). For other classes, or if the parameter is null, the return value is null.- Parameters:
cls
- the class to convert, may be null- Returns:
- the corresponding primitive type if
cls
is a wrapper class, null otherwise
-
wrappersToPrimitives
Converts the specified array of wrapper Class objects to an array of its corresponding primitive Class objects.
This method invokes
wrapperToPrimitive()
for each element of the passed in array.- Parameters:
classes
- the class array to convert, may be null or empty- Returns:
- an array which contains for each given class, the primitive class or
null if the original class is not a wrapper class.
null
if null input. Empty array if an empty array passed in. - See Also:
-