anderix.datajets
Class Datum

java.lang.Object
  extended by anderix.datajets.Datum

public class Datum
extends java.lang.Object

A single piece of data retrieved from or to be stored in a database table. It contains methods to facilitate type converstions and testing object types. Every Datum contains an internal object of type Object and provides methods for testing the type and for casting to several other types. Use the following pattern to convert objects from one type to another:

//Example: convert an int to several types
int i = 1;
Datum d = new Datum(i);
String s = d.toString();
long l = d.toLong();
short sh = d.toShort();
The Datum class can convert to and from the following types: It also accepts and returns any Object, and its conversion methods may be useful for other types as well. However, this should be thoroughly tested for each type.

A Datum can also provide information about the type of internal object. To test for a specific type, use the following pattern:

//Example: test to determine type
int i = 1;
Datum d = new Datum(i);
boolean b = d.isInt(); //returns true
b = d.isString(); //returns false


Constructor Summary
Datum(boolean theObject)
          Creates a Datum object that contains a boolean.
Datum(byte theObject)
          Creates a Datum object that contains a byte.
Datum(double theObject)
          Creates a Datum object that contains a double.
Datum(float theObject)
          Creates a Datum object that contains a float.
Datum(int theObject)
          Creates a Datum object that contains an int.
Datum(long theObject)
          Creates a Datum object that contains a long.
Datum(java.lang.Object theObject)
          Creates a Datum object that contains any Object.
Datum(short theObject)
          Creates a Datum object that contains a boolean.
 
Method Summary
 boolean isBoolean()
          Tests whether the internal object is a Boolean or not.
 boolean isByte()
          Tests whether the internal object is a Byte or not.
 boolean isDate()
          Tests whether the internal object is a Date or not.
 boolean isDouble()
          Tests whether the internal object is a Double or not.
 boolean isFloat()
          Tests whether the internal object is a Float or not.
 boolean isInt()
          Tests whether the internal object is an Integer or not.
 boolean isLong()
          Tests whether the internal object is a Long or not.
 boolean isNull()
          Tests whether the internal object is null or not.
 boolean isShort()
          Tests whether the internal object is a Short or not.
 boolean isString()
          Tests whether the internal object is a String or not.
 boolean toBoolean()
          Converts the internal object to a boolean.
 byte toByte()
          Converts the internal object to a byte.
 java.util.Date toDate()
          Converts the internal object to a java.util.Date.
 double toDouble()
          Converts the internal object to a double.
 float toFloat()
          Converts the internal object to a float.
 int toInt()
          Converts the internal object to an int.
 long toLong()
          Converts the internal object to a long.
 java.lang.Object toObject()
          Returns the internal object as an Object.
 short toShort()
          Converts the internal object to a short.
 java.lang.String toString()
          Converts the internal object to a String object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Datum

public Datum(java.lang.Object theObject)
Creates a Datum object that contains any Object.

Parameters:
theObject - the Object to convert

Datum

public Datum(int theObject)
Creates a Datum object that contains an int.

Parameters:
theObject - the int to convert

Datum

public Datum(boolean theObject)
Creates a Datum object that contains a boolean.

Parameters:
theObject - the boolean to convert

Datum

public Datum(short theObject)
Creates a Datum object that contains a boolean.

Parameters:
theObject - the short to convert

Datum

public Datum(long theObject)
Creates a Datum object that contains a long.

Parameters:
theObject - the long to convert

Datum

public Datum(float theObject)
Creates a Datum object that contains a float.

Parameters:
theObject - the float to convert

Datum

public Datum(double theObject)
Creates a Datum object that contains a double.

Parameters:
theObject - the double to convert

Datum

public Datum(byte theObject)
Creates a Datum object that contains a byte.

Parameters:
theObject - the byte to convert
Method Detail

toObject

public java.lang.Object toObject()
Returns the internal object as an Object.

Returns:
the internal object as an Object

isNull

public boolean isNull()
Tests whether the internal object is null or not.

Returns:
true if the object is null; false otherwise

isString

public boolean isString()
Tests whether the internal object is a String or not.

Returns:
true if the object is of type String; false otherwise

isInt

public boolean isInt()
Tests whether the internal object is an Integer or not.

Returns:
true if the object is of type Integer; false otherwise

isDate

public boolean isDate()
Tests whether the internal object is a Date or not.

Returns:
true if the object is of type Date; false otherwise

isBoolean

public boolean isBoolean()
Tests whether the internal object is a Boolean or not.

Returns:
true if the object is of type Boolean; false otherwise

isShort

public boolean isShort()
Tests whether the internal object is a Short or not.

Returns:
true if the object is of type Short; false otherwise

isLong

public boolean isLong()
Tests whether the internal object is a Long or not.

Returns:
true if the object is of type Long; false otherwise

isFloat

public boolean isFloat()
Tests whether the internal object is a Float or not.

Returns:
true if the object is of type Float; false otherwise

isDouble

public boolean isDouble()
Tests whether the internal object is a Double or not.

Returns:
true if the object is of type Double; false otherwise

isByte

public boolean isByte()
Tests whether the internal object is a Byte or not.

Returns:
true if the object is of type Byte; false otherwise

toString

public java.lang.String toString()
Converts the internal object to a String object. This conversion relies on the .toString() method of the object. If the object cannot be converted, an empty string is returned.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the internal object

toInt

public int toInt()
Converts the internal object to an int. If the object cannot be converted, a value of 0 is returned.

Returns:
the internal object as an int

toDate

public java.util.Date toDate()
Converts the internal object to a java.util.Date. If the object cannot be converted, a value representing "the epoch", namely January 1, 1970, 00:00:00 GMT, is returned.

Returns:
the internal object as a Date

toBoolean

public boolean toBoolean()
Converts the internal object to a boolean.

Returns:
the internal object as a boolean If the object cannot be converted, a value of false is returned.

toShort

public short toShort()
Converts the internal object to a short. If the object cannot be converted, a value of 0 is returned.

Returns:
the internal object as a short

toLong

public long toLong()
Converts the internal object to a long. If the object cannot be converted, a value of 0 is returned.

Returns:
the internal object as a long

toFloat

public float toFloat()
Converts the internal object to a float. If the object cannot be converted, a value of 0 is returned.

Returns:
the internal object as a float

toDouble

public double toDouble()
Converts the internal object to a double. If the object cannot be converted, a value of 0 is returned.

Returns:
the internal object as a double

toByte

public byte toByte()
Converts the internal object to a byte. If the object cannot be converted, a value of 0 is returned.

Returns:
the internal object as a byte