Savarese.Org

org.savarese.unicorn.util
Class Types

java.lang.Object
  extended by org.savarese.unicorn.util.Types

public final class Types
extends java.lang.Object

A singleton class storing convenience methods for converting from and to string representations of objects.


Method Summary
static java.lang.String arrayToString(java.lang.Object[] values)
          Converts an arrray of values to a string representation used by Commons BeanUtils.
static java.lang.String convert(java.lang.Object value)
          Converts a value to a string representation, converting arrays with arrayToString(java.lang.Object[]) and other objects with Commons BeanUtils.
static java.lang.Object convert(java.lang.String value, java.lang.Class type)
          Converts a string representation of a value to an object of a specified type.
static java.lang.Class getClass(java.lang.String name)
          Returns the class object corresponding to the given type name.
static java.lang.String[] stringToStringArray(java.lang.String values)
          Convert a string representation of a string array to an array of strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getClass

public static final java.lang.Class getClass(java.lang.String name)
                                      throws java.lang.ClassNotFoundException
Returns the class object corresponding to the given type name. Maps primitive type names to their java.lang wrapper classes.

Parameters:
name - The name of the type to retrieve.
Returns:
The class object corresponding to the given type name.
Throws:
java.lang.ClassNotFoundException - If a class corresponding to the name cannot be found.

arrayToString

public static final java.lang.String arrayToString(java.lang.Object[] values)
Converts an arrray of values to a string representation used by Commons BeanUtils. For example,

{ "value1", "value2", "value3" }

Parameters:
values - The array of values to convert.
Returns:
The string representation of the array.

stringToStringArray

public static final java.lang.String[] stringToStringArray(java.lang.String values)
Convert a string representation of a string array to an array of strings.

Parameters:
values - The string representation to convert.
Returns:
The array of strings.

convert

public static java.lang.String convert(java.lang.Object value)
Converts a value to a string representation, converting arrays with arrayToString(java.lang.Object[]) and other objects with Commons BeanUtils.

Parameters:
value - The value to convert.
Returns:
The string representation of the value.

convert

public static java.lang.Object convert(java.lang.String value,
                                       java.lang.Class type)
                                throws java.lang.Exception
Converts a string representation of a value to an object of a specified type.

Parameters:
value - The string value to convert.
type - The type of the object to convert to.
Returns:
The object representation of the value.
Throws:
java.lang.Exception - If there is a problem converting the value.

Savarese.Org

Copyright © 2006 Daniel F. Savarese. All Rights Reserved.