Class TypeUtil


  • public class TypeUtil
    extends java.lang.Object
    Utility class for working with Java types supported by BeanIO.
    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Class<? extends java.util.Collection<java.lang.Object>> ARRAY_TYPE
      Class type used to indicate a Java array
      static java.lang.String CALENDAR_DATE_ALIAS
      Alias for a java.util.Calendar that includes only date information
      static java.lang.String CALENDAR_DATETIME_ALIAS
      Alias for a java.util.Calendar that includes both date and time information.
      static java.lang.String CALENDAR_TIME_ALIAS
      Alias for a java.util.Calendar that includes only time information
      static java.lang.String DATE_ALIAS
      Alias for the java.util.Date class that includes only date information
      static java.lang.String DATETIME_ALIAS
      Alias for a java.util.Date that includes both date and time information.
      static java.lang.String TIME_ALIAS
      Alias for a java.util.Date that includes only time information
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isAliasOnly​(java.lang.String alias)
      Returns true if the type alias is not used to register a type handler for its associated class.
      static boolean isAssignable​(java.lang.Class<?> to, java.lang.Class<?> from)
      Returns true if to.isAssignableFrom(from) after converting primitive values of to to its object counterpart.
      static java.lang.Class<?> toAggregationType​(java.lang.String type)  
      static java.lang.Class<?> toBeanType​(java.lang.ClassLoader classLoader, java.lang.String type)  
      static java.lang.Class<? extends java.util.Collection<java.lang.Object>> toCollectionType​(java.lang.String type)
      Returns the collection Class object for a collection class name or type alias.
      static java.lang.Class<?> toType​(java.lang.ClassLoader classLoader, java.lang.String type)
      Returns the Class object for a class name or type alias.
      static java.lang.Class<?> toWrapperClass​(java.lang.Class<?> type)
      Converts primitive types to their wrapper counterparts.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DATETIME_ALIAS

        public static final java.lang.String DATETIME_ALIAS
        Alias for a java.util.Date that includes both date and time information. If a type handler is registered using this alias, the registered type handler will become the default type handler for all Date classes.
        See Also:
        Constant Field Values
      • DATE_ALIAS

        public static final java.lang.String DATE_ALIAS
        Alias for the java.util.Date class that includes only date information
        See Also:
        Constant Field Values
      • TIME_ALIAS

        public static final java.lang.String TIME_ALIAS
        Alias for a java.util.Date that includes only time information
        See Also:
        Constant Field Values
      • CALENDAR_DATETIME_ALIAS

        public static final java.lang.String CALENDAR_DATETIME_ALIAS
        Alias for a java.util.Calendar that includes both date and time information. If a type handler is registered using this alias, the registered type handler will become the default type handler for all Calendar classes.
        See Also:
        Constant Field Values
      • CALENDAR_TIME_ALIAS

        public static final java.lang.String CALENDAR_TIME_ALIAS
        Alias for a java.util.Calendar that includes only time information
        See Also:
        Constant Field Values
      • CALENDAR_DATE_ALIAS

        public static final java.lang.String CALENDAR_DATE_ALIAS
        Alias for a java.util.Calendar that includes only date information
        See Also:
        Constant Field Values
      • ARRAY_TYPE

        public static final java.lang.Class<? extends java.util.Collection<java.lang.Object>> ARRAY_TYPE
        Class type used to indicate a Java array
    • Method Detail

      • isAssignable

        public static boolean isAssignable​(java.lang.Class<?> to,
                                           java.lang.Class<?> from)
        Returns true if to.isAssignableFrom(from) after converting primitive values of to to its object counterpart.
        Parameters:
        to - the class or primitive to test assignability to
        from - the class to test assignability from
        Returns:
        true if to is assignable from from
      • toWrapperClass

        public static java.lang.Class<?> toWrapperClass​(java.lang.Class<?> type)
        Converts primitive types to their wrapper counterparts.
        Parameters:
        type - the class type to convert
        Returns:
        the wrapper equivalent for the primitive type, or if type was not a primitive, its returned as is
      • toType

        public static java.lang.Class<?> toType​(java.lang.ClassLoader classLoader,
                                                java.lang.String type)
        Returns the Class object for a class name or type alias. A type alias is not case sensitive. The following type aliases are supported:
        AliasClass or Primitive
        stringjava.lang.String
        booleanjava.lang.Boolean
        bytejava.lang.Byte
        intjava.lang.Integer
        integerjava.lang.Integer
        shortjava.lang.Short
        charjava.lang.Character
        characterjava.lang.Character
        longjava.lang.Long
        floatjava.lang.Float
        doublejava.lang.Double
        bigdecimaljava.math.BigDecimal
        decimaljava.math.BigDecimal
        bigintegerjava.math.BigInteger
        uuidjava.util.UUID
        urljava.net.URL
        datejava.util.Date
        timejava.util.Date
        datetimejava.util.Date
        calendarjava.util.Calendar
        Parameters:
        classLoader - the ClassLoader for loading classes
        type - the fully qualified class name or type alias
        Returns:
        the class, or null if the type name is invalid
      • isAliasOnly

        public static boolean isAliasOnly​(java.lang.String alias)
        Returns true if the type alias is not used to register a type handler for its associated class.
        Parameters:
        alias - the type alias to check
        Returns:
        true if the type alias is only an alias
      • toCollectionType

        public static java.lang.Class<? extends java.util.Collection<java.lang.Object>> toCollectionType​(java.lang.String type)
        Returns the collection Class object for a collection class name or type alias. A type alias is not case sensitive. The following collection type aliases are supported:
        AliasClass or Primitive
        arrayJava Array
        listjava.util.ArrayList
        setjava.util.HashSet
        Parameters:
        type - the fully qualified class name or type alias of the collection
        Returns:
        the collection class, or ARRAY_TYPE for array, or null if the type name is invalid
      • toAggregationType

        public static java.lang.Class<?> toAggregationType​(java.lang.String type)
      • toBeanType

        public static java.lang.Class<?> toBeanType​(java.lang.ClassLoader classLoader,
                                                    java.lang.String type)