BeanIO 1.2.3

org.beanio.util
Class TypeUtil

java.lang.Object
  extended by org.beanio.util.TypeUtil

public class TypeUtil
extends Object

Utility class for working with Java types supported by BeanIO.

Since:
1.0
Author:
Kevin Seim

Field Summary
static Class<? extends Collection<Object>> ARRAY_TYPE
          Class type used to indicate a Java array
static String DATE_ALIAS
          Alias for the java.util.Date class that includes only date information
static String DATETIME_ALIAS
          Alias for a java.util.Date that includes both date and time information.
static String TIME_ALIAS
          Alias for a java.util.Date that only includes only time information
 
Method Summary
static boolean isAliasOnly(String alias)
          Returns true if the type alias is not used to register a type handler for its associated class.
static boolean isAssignable(Class<?> to, Class<?> from)
          Returns true if to.isAssignableFrom(from) after converting primitive values of to to its object counterpart.
static Class<?> loadClass(String name)
          Loads a named class.
static Class<? extends Collection<Object>> toCollectionType(String type)
          Returns the collection Class object for a collection class name or type alias.
static Class<?> toType(String type)
          Returns the Class object for a class name or type alias.
static Class<?> toWrapperClass(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 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 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 String TIME_ALIAS
Alias for a java.util.Date that only includes only time information

See Also:
Constant Field Values

ARRAY_TYPE

public static final Class<? extends Collection<Object>> ARRAY_TYPE
Class type used to indicate a Java array

Method Detail

isAssignable

public static boolean isAssignable(Class<?> to,
                                   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 Class<?> toWrapperClass(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 Class<?> toType(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
datejava.util.Date
timejava.util.Date
datetimejava.util.Date

Parameters:
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(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 Class<? extends Collection<Object>> toCollectionType(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

loadClass

public static Class<?> loadClass(String name)
                          throws ClassNotFoundException
Loads a named class. If set, the current thread's context class loader is used before delegating to the default class loader used to load this class.

Parameters:
name - the name of the class to load
Returns:
the loaded Class
Throws:
ClassNotFoundException - if the class failed to load
Since:
1.2.2

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim