gov.sns.tools.data
Class GenericRecord

java.lang.Object
  |
  +--gov.sns.tools.data.GenericRecord
All Implemented Interfaces:
DataListener

public class GenericRecord
extends java.lang.Object
implements DataListener

GenericRecord is the default record class for DataTable. This class can be used directly for the records or a subclass of GenericRecord may be used for convenience. GenericRecord stores its data as key/value pairs.


Nested Class Summary
 class GenericRecord.ParseException
          A runtime exception thrown while attempting to parse values stored as strings into an object of the appropriate type.
 
Field Summary
protected  java.util.Map attributeTable
           
protected  DataTable table
           
 
Constructor Summary
GenericRecord(DataTable aTable)
          Creates new GenericRecord
 
Method Summary
 boolean booleanValueForKey(java.lang.String key)
          Convenience method to get the value as a boolean associated with the specified key.
 java.lang.String dataLabel()
          dataLabel() provides the name used to identify the class in an external data source.
 double doubleValueForKey(java.lang.String key)
          Convenience method to get the value as a double associated with the specified key.
 int intValueForKey(java.lang.String key)
          Convenience method to get the value as an int associated with the specified key.
 java.util.Set keys()
          Get the keys used in this record.
 long longValueForKey(java.lang.String key)
          Convenience method to get the value as a long associated with the specified key.
 java.lang.Number numberForKey(java.lang.String key)
          Convenience method to get the value cast as a number associated with the specified key.
 void setValueForKey(boolean value, java.lang.String key)
          Set the boolean value to associate with the specified key.
 void setValueForKey(double value, java.lang.String key)
          Set the double value to associate with the specified key.
 void setValueForKey(int value, java.lang.String key)
          Set the int value to associate with the specified key.
 void setValueForKey(long value, java.lang.String key)
          Set the long value to associate with the specified key.
 void setValueForKey(java.lang.Object value, java.lang.String key)
          Set the value to associate with the specified key.
 java.lang.String stringValueForKey(java.lang.String key)
          Convenience method to get the value as a String associated with the specified key.
 java.lang.String toString()
          Overrides toString() to show key/value pairs.
 void update(DataAdaptor adaptor)
          Update the data based on the information provided by the data provider.
 java.lang.Object valueForKey(java.lang.String key)
          Get the value associated with the specified key.
 java.util.Collection values()
          Get the collection of values held in this record.
 void write(DataAdaptor adaptor)
          Write data to the data adaptor for storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

table

protected DataTable table

attributeTable

protected java.util.Map attributeTable
Constructor Detail

GenericRecord

public GenericRecord(DataTable aTable)
Creates new GenericRecord

Method Detail

keys

public java.util.Set keys()
Get the keys used in this record.

Returns:
The keys used in this record.

values

public java.util.Collection values()
Get the collection of values held in this record.

Returns:
The collection of values held in this record.

valueForKey

public java.lang.Object valueForKey(java.lang.String key)
Get the value associated with the specified key.

Parameters:
key - The key for which to get the associated value.
Returns:
The value as an Object.

setValueForKey

public void setValueForKey(java.lang.Object value,
                           java.lang.String key)
Set the value to associate with the specified key. If the value associated with a primary key is changed we must be careful to force the table to re-index the record.

Parameters:
value - The new value to associate with the specified key.
key - The key for which to associated the new value.

numberForKey

public java.lang.Number numberForKey(java.lang.String key)
Convenience method to get the value cast as a number associated with the specified key.

Parameters:
key - The key for which to get the associated value.
Returns:
The value as an Number.
Throws:
java.lang.ClassCastException - if the value cannot be cast as a Number.

booleanValueForKey

public boolean booleanValueForKey(java.lang.String key)
Convenience method to get the value as a boolean associated with the specified key.

Parameters:
key - The key for which to get the associated value.
Returns:
The value as an boolean.
Throws:
java.lang.ClassCastException - if the value cannot be cast as a Boolean.

setValueForKey

public void setValueForKey(boolean value,
                           java.lang.String key)
Set the boolean value to associate with the specified key.

Parameters:
value - The new boolean value to associate with the specified key.
key - The key for which to associated the new value.

intValueForKey

public int intValueForKey(java.lang.String key)
Convenience method to get the value as an int associated with the specified key.

Parameters:
key - The key for which to get the associated value.
Returns:
The value as an int.
Throws:
java.lang.ClassCastException - if the value cannot be cast as a Number.

setValueForKey

public void setValueForKey(int value,
                           java.lang.String key)
Set the int value to associate with the specified key.

Parameters:
value - The new int value to associate with the specified key.
key - The key for which to associated the new value.

longValueForKey

public long longValueForKey(java.lang.String key)
Convenience method to get the value as a long associated with the specified key.

Parameters:
key - The key for which to get the associated value.
Returns:
The value as a long.
Throws:
java.lang.ClassCastException - if the value cannot be cast as a Number.

setValueForKey

public void setValueForKey(long value,
                           java.lang.String key)
Set the long value to associate with the specified key.

Parameters:
value - The new long value to associate with the specified key.
key - The key for which to associated the new value.

doubleValueForKey

public double doubleValueForKey(java.lang.String key)
Convenience method to get the value as a double associated with the specified key.

Parameters:
key - The key for which to get the associated value.
Returns:
The value as a double.
Throws:
java.lang.ClassCastException - if the value cannot be cast as a Number.

setValueForKey

public void setValueForKey(double value,
                           java.lang.String key)
Set the double value to associate with the specified key.

Parameters:
value - The new double value to associate with the specified key.
key - The key for which to associated the new value.

stringValueForKey

public java.lang.String stringValueForKey(java.lang.String key)
Convenience method to get the value as a String associated with the specified key.

Parameters:
key - The key for which to get the associated value.
Returns:
The value as an String.
Throws:
java.lang.ClassCastException - if the value cannot be cast as a String.

toString

public java.lang.String toString()
Overrides toString() to show key/value pairs.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of the record.

dataLabel

public java.lang.String dataLabel()
dataLabel() provides the name used to identify the class in an external data source.

Specified by:
dataLabel in interface DataListener
Returns:
a tag that identifies the receiver's type

update

public void update(DataAdaptor adaptor)
            throws GenericRecord.ParseException
Update the data based on the information provided by the data provider.

Specified by:
update in interface DataListener
Parameters:
adaptor - The adaptor from which to update the data
GenericRecord.ParseException

write

public void write(DataAdaptor adaptor)
Write data to the data adaptor for storage.

Specified by:
write in interface DataListener
Parameters:
adaptor - The adaptor to which the receiver's data is written