com.silentq.util
Class Conversions

java.lang.Object
  |
  +--com.silentq.util.Conversions

public class Conversions
extends java.lang.Object
implements java.io.Serializable

This class handles conversions between types. Each primitive type has its own method, and tries to make a best-guess conversion.

See Also:
Serialized Form

Constructor Summary
Conversions()
           
 
Method Summary
protected static boolean convertToBoolean(java.lang.Object obj)
          Returns true if the value is a Number and not equal to 0, a character equal to 't' or 'T', a boolean true value, or a String "true".
protected static byte convertToByte(java.lang.Object obj)
          Returns Number.byteValue() if possible, 1 for true, 0 for false, or new Byte(toString).byteValue().
protected static char convertToChar(java.lang.Object obj)
          Returns the first character of a Number converted to a String, 't' for a boolean true value, 'f' for a boolean false value, or the first character in obj.toString().
protected static double convertToDouble(java.lang.Object obj)
          Returns Number.doubleValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Double(toString).doubleValue().
protected static float convertToFloat(java.lang.Object obj)
          Returns Number.floatValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Float(toString).floatValue().
protected static int convertToInt(java.lang.Object obj)
          Returns Number.intValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Integer(toString).intValue().
protected static long convertToLong(java.lang.Object obj)
          Returns Number.longValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Long(toString).longValue().
protected static short convertToShort(java.lang.Object obj)
          Returns Number.shortValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Short(toString).shortValue().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Conversions

public Conversions()
Method Detail

convertToInt

protected static int convertToInt(java.lang.Object obj)
Returns Number.intValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Integer(toString).intValue(). It returns 0 if no conversion is successful.

convertToByte

protected static byte convertToByte(java.lang.Object obj)
Returns Number.byteValue() if possible, 1 for true, 0 for false, or new Byte(toString).byteValue(). It returns 0 if no conversion is successful.

convertToLong

protected static long convertToLong(java.lang.Object obj)
Returns Number.longValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Long(toString).longValue(). It returns 0 if no conversion is successful.

convertToShort

protected static short convertToShort(java.lang.Object obj)
Returns Number.shortValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Short(toString).shortValue(). It returns 0 if no conversion is successful.

convertToFloat

protected static float convertToFloat(java.lang.Object obj)
Returns Number.floatValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Float(toString).floatValue(). It returns 0 if no conversion is successful.

convertToDouble

protected static double convertToDouble(java.lang.Object obj)
Returns Number.doubleValue() if possible, 1 for true, 0 for false, the digit if it's a character and a digit, or new Double(toString).doubleValue(). It returns 0 if no conversion is successful.

convertToBoolean

protected static boolean convertToBoolean(java.lang.Object obj)
Returns true if the value is a Number and not equal to 0, a character equal to 't' or 'T', a boolean true value, or a String "true". Otherwise it returns false.

convertToChar

protected static char convertToChar(java.lang.Object obj)
Returns the first character of a Number converted to a String, 't' for a boolean true value, 'f' for a boolean false value, or the first character in obj.toString(). If it throws an exception, it returns '?'.