net.wotonomy.foundation.internal
Class ValueConverter

java.lang.Object
  extended by net.wotonomy.foundation.internal.ValueConverter

public class ValueConverter
extends java.lang.Object

A utility class to convert objects to a desired class.

Version:
$Revision: 893 $
Author:
michael@mpowers.net, $Author: cgruber $

Constructor Summary
ValueConverter()
           
 
Method Summary
protected static java.lang.Object convert(java.lang.Object anObject, java.lang.Class aClass)
          Called by convertObjectToClass() when we need to convert to an unrecognized type.
static java.lang.Object convertObjectToClass(java.lang.Object anObject, java.lang.Class aClass)
          Returns the specified object as converted to an instance of the specified class, or null if the conversion could not be performed.
static java.lang.Object getArray(java.lang.Object anObject, java.lang.Class anArrayClass)
          Convert the object to the specified array type.
static java.lang.Boolean getBoolean(java.lang.Object anObject)
          Numbers equal to zero are true; Strings equal to "yes" are true; Strings are then passed to the Boolean constructor.
static boolean getBooleanValue(java.lang.Object anObject)
          Calls getBoolean and converts result to primitive.
static java.lang.Byte getByte(java.lang.Object anObject)
           
static byte getByteValue(java.lang.Object anObject)
           
static java.lang.Character getCharacter(java.lang.Object anObject)
           
static char getCharValue(java.lang.Object anObject)
           
static java.util.Collection getCollection(java.lang.Object anObject, java.lang.Class aCollectionClass)
          Converts the object into the specified collection class.
static java.util.Date getDate(java.lang.Object anObject)
          Get an appropriate Date from the given object.
static java.text.DateFormat getDateFormat()
           
static java.lang.Double getDouble(java.lang.Object anObject)
           
static double getDoubleValue(java.lang.Object anObject)
           
static java.lang.Float getFloat(java.lang.Object anObject)
           
static float getFloatValue(java.lang.Object anObject)
           
static java.lang.Integer getInteger(java.lang.Object anObject)
           
static int getIntValue(java.lang.Object anObject)
           
static java.lang.Long getLong(java.lang.Object anObject)
           
static long getLongValue(java.lang.Object anObject)
           
static java.lang.Short getShort(java.lang.Object anObject)
           
static short getShortValue(java.lang.Object anObject)
           
static java.lang.String getString(java.lang.Object anObject)
          Get an appropriate String representation for the object.
static java.lang.Object invert(java.lang.Object anObject)
          Returns the "inverted" value of the specified object.
protected static java.lang.Object preprocess(java.lang.Object anObject)
          Tries to convert all objects to either Numbers or objects that will produce a parsable toString result.
static void setDateFormat(java.text.DateFormat aDateFormat)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValueConverter

public ValueConverter()
Method Detail

convertObjectToClass

public static java.lang.Object convertObjectToClass(java.lang.Object anObject,
                                                    java.lang.Class aClass)
Returns the specified object as converted to an instance of the specified class, or null if the conversion could not be performed.


convert

protected static java.lang.Object convert(java.lang.Object anObject,
                                          java.lang.Class aClass)
Called by convertObjectToClass() when we need to convert to an unrecognized type. This implementation scans the constructors of the specified class for the best fit to the object. and returns a new instance with that constructor. Subclasses can override to directly support specific types.


preprocess

protected static java.lang.Object preprocess(java.lang.Object anObject)
Tries to convert all objects to either Numbers or objects that will produce a parsable toString result.


getShortValue

public static short getShortValue(java.lang.Object anObject)

getShort

public static java.lang.Short getShort(java.lang.Object anObject)

getIntValue

public static int getIntValue(java.lang.Object anObject)

getInteger

public static java.lang.Integer getInteger(java.lang.Object anObject)

getLongValue

public static long getLongValue(java.lang.Object anObject)

getLong

public static java.lang.Long getLong(java.lang.Object anObject)

getDoubleValue

public static double getDoubleValue(java.lang.Object anObject)

getDouble

public static java.lang.Double getDouble(java.lang.Object anObject)

getFloatValue

public static float getFloatValue(java.lang.Object anObject)

getFloat

public static java.lang.Float getFloat(java.lang.Object anObject)

getCharValue

public static char getCharValue(java.lang.Object anObject)

getCharacter

public static java.lang.Character getCharacter(java.lang.Object anObject)

getByteValue

public static byte getByteValue(java.lang.Object anObject)

getByte

public static java.lang.Byte getByte(java.lang.Object anObject)

getBooleanValue

public static boolean getBooleanValue(java.lang.Object anObject)
Calls getBoolean and converts result to primitive.


getBoolean

public static java.lang.Boolean getBoolean(java.lang.Object anObject)
Numbers equal to zero are true; Strings equal to "yes" are true; Strings are then passed to the Boolean constructor. Other values return null.


getString

public static java.lang.String getString(java.lang.Object anObject)
Get an appropriate String representation for the object. Nulls are converted to "null". Date are formatted according to the current date format. All else uses toString.


getCollection

public static java.util.Collection getCollection(java.lang.Object anObject,
                                                 java.lang.Class aCollectionClass)
Converts the object into the specified collection class. If unable to convert in any other way, resorts to creating a new collection of the specified type containing the specified object.


getArray

public static java.lang.Object getArray(java.lang.Object anObject,
                                        java.lang.Class anArrayClass)
Convert the object to the specified array type.


getDate

public static java.util.Date getDate(java.lang.Object anObject)
Get an appropriate Date from the given object.


getDateFormat

public static java.text.DateFormat getDateFormat()

setDateFormat

public static void setDateFormat(java.text.DateFormat aDateFormat)

invert

public static java.lang.Object invert(java.lang.Object anObject)
Returns the "inverted" value of the specified object. Numbers except for chars and bytes are converted to their negative representation. Chars and bytes are treated as booleans. String are converted to booleans. Booleans are converted to their opposite. All other types return null.



Copyright © 2006 null. All Rights Reserved.