Class GenericRecord

java.lang.Object
xal.tools.data.GenericRecord
All Implemented Interfaces:
DataListener, KeyedRecord

public class GenericRecord extends Object implements KeyedRecord, 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. Note that GenericRecord is not thread safe. This is due to the fact that DataTable is not thread safe.
Author:
tap
  • Field Details

    • dataTable

      protected final DataTable dataTable
      data table to which this record belongs
    • attributeTable

      protected final Map<String,Object> attributeTable
      table of attributes by attribute ID
  • Constructor Details

    • GenericRecord

      public GenericRecord(DataTable aTable)
      Creates new GenericRecord
  • Method Details

    • keys

      public Set<String> keys()
      Get the keys used in this record.
      Returns:
      The keys used in this record.
    • values

      public Collection<Object> values()
      Get the collection of values held in this record.
      Returns:
      The collection of values held in this record.
    • hasAttributeForKey

      public boolean hasAttributeForKey(String key)
      Determine whether this record has the specified attribute
    • valueForKey

      public Object valueForKey(String key)
      Get the value associated with the specified key.
      Specified by:
      valueForKey in interface KeyedRecord
      Parameters:
      key - The key for which to get the associated value.
      Returns:
      The value as an Object.
    • setValueForKey

      public void setValueForKey(Object value, 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 Number numberForKey(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:
      ClassCastException - if the value cannot be cast as a Number.
    • booleanValueForKey

      public boolean booleanValueForKey(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:
      ClassCastException - if the value cannot be cast as a Boolean.
    • setValueForKey

      public void setValueForKey(boolean value, 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(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:
      ClassCastException - if the value cannot be cast as a Number.
    • setValueForKey

      public void setValueForKey(int value, 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(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:
      ClassCastException - if the value cannot be cast as a Number.
    • setValueForKey

      public void setValueForKey(long value, 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(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:
      ClassCastException - if the value cannot be cast as a Number.
    • setValueForKey

      public void setValueForKey(double value, 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 String stringValueForKey(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:
      ClassCastException - if the value cannot be cast as a String.
    • toString

      public String toString()
      Overrides toString() to show key/value pairs.
      Overrides:
      toString in class Object
      Returns:
      The string representation of the record.
    • dataLabel

      public 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
      Throws:
      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