Package com.aspectran.core.util
Class TypeUtils
- java.lang.Object
-
- com.aspectran.core.util.TypeUtils
-
public abstract class TypeUtils extends java.lang.ObjectUtility methods focusing on type inspection, particularly with regard to generics.
-
-
Constructor Summary
Constructors Constructor Description TypeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Class<?>getPrimitiveWrapper(java.lang.Class<?> primitiveType)Gets the wrapper object class for the given primitive type class.static booleanisAssignable(java.lang.Class<?> lhsType, java.lang.Class<?> rhsType)Check if the right-hand side type may be assigned to the left-hand side type, assuming setting by reflection.static booleanisAssignableValue(java.lang.Class<?> type, java.lang.Object value)Determine if the given type is assignable from the given value, assuming setting by reflection.static booleanisPrimitiveArray(java.lang.Class<?> clazz)Check if the given class represents an array of primitives, i.e.static booleanisPrimitiveWrapper(java.lang.Class<?> clazz)Check if the given class represents a primitive wrapper, i.e.static booleanisPrimitiveWrapperArray(java.lang.Class<?> clazz)Check if the given class represents an array of primitive wrappers, i.e.static java.lang.Class<?>[]wrappersToPrimitives(java.lang.Class<?>[] classes)Converts the specified array of wrapper Class objects to an array of its corresponding primitive Class objects.static java.lang.Class<?>wrapperToPrimitive(java.lang.Class<?> cls)Converts the specified wrapper class to its corresponding primitive class.
-
-
-
Method Detail
-
isPrimitiveWrapper
public static boolean isPrimitiveWrapper(java.lang.Class<?> clazz)
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
public static boolean isPrimitiveArray(java.lang.Class<?> clazz)
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
public static boolean isPrimitiveWrapperArray(java.lang.Class<?> clazz)
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
public static boolean isAssignable(java.lang.Class<?> lhsType, java.lang.Class<?> rhsType)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
public static boolean isAssignableValue(java.lang.Class<?> type, java.lang.Object value)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
public static java.lang.Class<?> getPrimitiveWrapper(java.lang.Class<?> primitiveType)
Gets the wrapper object class for the given primitive type class. For example, passingboolean.classreturnsBoolean.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
public static java.lang.Class<?> wrapperToPrimitive(java.lang.Class<?> cls)
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.TYPEforInteger.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
clsis a wrapper class, null otherwise
-
wrappersToPrimitives
public static java.lang.Class<?>[] wrappersToPrimitives(java.lang.Class<?>[] classes)
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.
nullif null input. Empty array if an empty array passed in. - See Also:
wrapperToPrimitive(Class)
-
-