Class TypeUtils

java.lang.Object
com.aspectran.utils.TypeUtils

public abstract class TypeUtils extends Object
Utility methods focusing on type inspection, particularly with regard to generics.
  • Constructor Details

    • TypeUtils

      public TypeUtils()
  • Method Details

    • isPrimitiveWrapper

      public static boolean isPrimitiveWrapper(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(@NonNull 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(@NonNull 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(Class<?> lhsType, 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 type
      rhsType - 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(Class<?> type, 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 type
      value - the value that should be assigned to the type
      Returns:
      if the type is assignable from the value
    • getPrimitiveWrapper

      public static Class<?> getPrimitiveWrapper(Class<?> primitiveType)
      Gets the wrapper object class for the given primitive type class. For example, passing boolean.class returns Boolean.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 Class<?> wrapperToPrimitive(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.TYPE for Integer.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

      public static Class<?>[] wrappersToPrimitives(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. null if null input. Empty array if an empty array passed in.
      See Also: