org.norther.tammi.acorn.util.converter
Class Types

java.lang.Object
  extended by org.norther.tammi.acorn.util.converter.Types

public abstract class Types
extends Object

Converts between primitive types and lang classes.

Author:
Ilkka Priha

Field Summary
static String BOOLEAN_CLASS_NAME
          Boolean class name.
static String BOOLEAN_TYPE
          boolean type.
static String BYTE_CLASS_NAME
          Byte class name.
static String BYTE_TYPE
          byte type.
static String CHAR_TYPE
          char type.
static String CHARACTER_CLASS_NAME
          Character class name.
static String DOUBLE_CLASS_NAME
          Double class name.
static String DOUBLE_TYPE
          double type.
static String FLOAT_CLASS_NAME
          Float class name.
static String FLOAT_TYPE
          float type.
static String INT_TYPE
          int type.
static String INTEGER_CLASS_NAME
          Integer class name.
static String LONG_CLASS_NAME
          Long class name.
static String LONG_TYPE
          long type.
static Integer MINUS
          Minus.
static Double NAN
          NaN.
static String NULL_STRING
          The string representation of null.
static String OBJECT_CLASS_NAME
          Object class name.
static Integer PLUS
          Plus.
static String SHORT_CLASS_NAME
          Short class name.
static String SHORT_TYPE
          short type.
static String STRING_CLASS_NAME
          String class name.
static Integer ZERO
          Zero.
 
Constructor Summary
Types()
           
 
Method Summary
static ClassLoader getClassLoader()
          Gets a class loader.
static boolean isArrayType(String className)
          Checks whether the specified class type is an array.
static boolean isCharSequenceType(String className, boolean arrayp)
          Checks whether the specified class type is a char sequence, i.e.
static boolean isNaN(Number number)
          Checks whether the specified number is a NaN.
static boolean isNumericType(String className, boolean arrayp)
          Checks whether the specified class type is numeric, i.e.
static boolean isPrimitiveType(String className)
          Checks whether the specified class type is primitive.
static boolean isStringType(String className, boolean arrayp)
          Checks whether the specified class type is a string.
static boolean toBoolean(String str)
          Converts a string to a boolean.
static byte toByte(String str)
          Converts a string to a byte.
static String toComponentType(String className)
          Converts the specified array type to the corresponding component type.
static int toInt(String str)
          Converts a string to an int.
static long toLong(String str)
          Converts a string to a long.
static Number toNumber(String str, String type)
          Converts a string to a number.
static Class toObjectClass(Class type)
          Converts a primitive type to its corresponding object class.
static String toObjectType(String primitive)
          Converts a primitive type to the corresponding object type.
static String toPlainType(Class clazz)
          Converts a class to its plain non-qualified component type.
static String toPlainType(String className)
          Converts a class name to its plain non-qualified component type.
static String toPrimitiveArrayType(String className)
          Converts an object type to the corresponding primitive array type.
static Class toPrimitiveClass(Class clazz)
          Converts a class to its corresponding primitive type.
static Class toPrimitiveClass(String className)
          Converts a named class to its corresponding primitive type.
static String toPrimitiveType(String className)
          Converts an object type to the corresponding primitive type.
static short toShort(String str)
          Converts a string to a short.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_STRING

public static final String NULL_STRING
The string representation of null.


NAN

public static final Double NAN
NaN.


ZERO

public static final Integer ZERO
Zero.


PLUS

public static final Integer PLUS
Plus.


MINUS

public static final Integer MINUS
Minus.


BYTE_TYPE

public static final String BYTE_TYPE
byte type.


CHAR_TYPE

public static final String CHAR_TYPE
char type.


SHORT_TYPE

public static final String SHORT_TYPE
short type.


INT_TYPE

public static final String INT_TYPE
int type.


LONG_TYPE

public static final String LONG_TYPE
long type.


FLOAT_TYPE

public static final String FLOAT_TYPE
float type.


DOUBLE_TYPE

public static final String DOUBLE_TYPE
double type.


BOOLEAN_TYPE

public static final String BOOLEAN_TYPE
boolean type.


BYTE_CLASS_NAME

public static final String BYTE_CLASS_NAME
Byte class name.


CHARACTER_CLASS_NAME

public static final String CHARACTER_CLASS_NAME
Character class name.


SHORT_CLASS_NAME

public static final String SHORT_CLASS_NAME
Short class name.


INTEGER_CLASS_NAME

public static final String INTEGER_CLASS_NAME
Integer class name.


LONG_CLASS_NAME

public static final String LONG_CLASS_NAME
Long class name.


FLOAT_CLASS_NAME

public static final String FLOAT_CLASS_NAME
Float class name.


DOUBLE_CLASS_NAME

public static final String DOUBLE_CLASS_NAME
Double class name.


BOOLEAN_CLASS_NAME

public static final String BOOLEAN_CLASS_NAME
Boolean class name.


STRING_CLASS_NAME

public static final String STRING_CLASS_NAME
String class name.


OBJECT_CLASS_NAME

public static final String OBJECT_CLASS_NAME
Object class name.

Constructor Detail

Types

public Types()
Method Detail

toBoolean

public static boolean toBoolean(String str)
Converts a string to a boolean.

Parameters:
str - the string to convert.
Returns:
the converted string.

toByte

public static byte toByte(String str)
Converts a string to a byte.

Parameters:
str - the string to convert.
Returns:
the converted string.

toShort

public static short toShort(String str)
Converts a string to a short.

Parameters:
str - the string to convert.
Returns:
the converted string.

toInt

public static int toInt(String str)
Converts a string to an int.

Parameters:
str - the string to convert.
Returns:
the converted string.

toLong

public static long toLong(String str)
Converts a string to a long.

Parameters:
str - the string to convert.
Returns:
the converted string.

toNumber

public static Number toNumber(String str,
                              String type)
Converts a string to a number.

Parameters:
str - the string to convert.
type - the requested type.
Returns:
the converted string or null.

isNaN

public static boolean isNaN(Number number)
Checks whether the specified number is a NaN.

Parameters:
number - the number to check.
Returns:
true for a NaN, otherwise false.

isNumericType

public static boolean isNumericType(String className,
                                    boolean arrayp)
Checks whether the specified class type is numeric, i.e. a subclass of java.lang.Number.

Parameters:
className - the class type to check.
arrayp - true if an array type is accepted.
Returns:
true for a numeric type, otherwise false.

isCharSequenceType

public static boolean isCharSequenceType(String className,
                                         boolean arrayp)
Checks whether the specified class type is a char sequence, i.e. implements java.lang.CharSequence.

Parameters:
className - the class type to check.
arrayp - true if an array type is accepted.
Returns:
true for a numeric type, otherwise false.

isStringType

public static boolean isStringType(String className,
                                   boolean arrayp)
Checks whether the specified class type is a string.

Parameters:
className - the class type to check.
arrayp - true if an array type is accepted.
Returns:
true for a numeric type, otherwise false.

isPrimitiveType

public static boolean isPrimitiveType(String className)
Checks whether the specified class type is primitive.

Parameters:
className - the class type to check.
Returns:
true for a primitive type, otherwise false.

isArrayType

public static boolean isArrayType(String className)
Checks whether the specified class type is an array.

Parameters:
className - the class type to check.
Returns:
true for an aray type, otherwise false.

toPrimitiveClass

public static Class toPrimitiveClass(String className)
Converts a named class to its corresponding primitive type. The component type is returned for arrays.

Parameters:
className - the class name to convert.
Returns:
the corresponding primitive type or null if not applicable.

toPrimitiveClass

public static Class toPrimitiveClass(Class clazz)
Converts a class to its corresponding primitive type. The component type is returned for arrays.

Parameters:
clazz - the class to convert.
Returns:
the corresponding primitive type or null if not applicable.

toObjectClass

public static Class toObjectClass(Class type)
Converts a primitive type to its corresponding object class. The component type is returned for arrays.

Parameters:
type - the primitive type to convert.
Returns:
the corresponding object class or the original one.

toComponentType

public static String toComponentType(String className)
Converts the specified array type to the corresponding component type.

Parameters:
className - the array type to convert.
Returns:
the corresponding component type.

toPrimitiveType

public static String toPrimitiveType(String className)
Converts an object type to the corresponding primitive type.

Parameters:
className - the object type to convert.
Returns:
the corresponding primitive type or null if not applicable.

toPrimitiveArrayType

public static String toPrimitiveArrayType(String className)
Converts an object type to the corresponding primitive array type.

Parameters:
className - the object type to convert.
Returns:
the corresponding primitive array type or null if not applicable.

toObjectType

public static String toObjectType(String primitive)
Converts a primitive type to the corresponding object type.

Parameters:
primitive - the primitive type to convert.
Returns:
the corresponding object type or the original one.

toPlainType

public static String toPlainType(Class clazz)
Converts a class to its plain non-qualified component type.

Parameters:
clazz - the class.
Returns:
the plain type.

toPlainType

public static String toPlainType(String className)
Converts a class name to its plain non-qualified component type.

Parameters:
className - the qualified class name.
Returns:
the plain type.

getClassLoader

public static ClassLoader getClassLoader()
Gets a class loader.

Returns:
the class loader.


Copyright © 2004 The Norther Organization. All rights reserved.