Class DataTable

java.lang.Object
xal.tools.data.DataTable

public class DataTable extends Object
**************************************************************************** DataTable is internal storage resembling a database table. An instance of DataTable consists of an associated schema and a number of records. Each record must be of the same class and have the same keys. Note that for performance reasons this class is not thread safe. Users who need thread safety must provide explicit synchronization on the table.
Author:
tap
  • Field Details

  • Constructor Details

  • Method Details

    • addDataTableListener

      public void addDataTableListener(DataTableListener listener)
      Add the specified listener as a receiver of events from this data table.
      Parameters:
      listener - the listener to receive events
    • removeDataTableListener

      public void removeDataTableListener(DataTableListener listener)
      Remove the specified listener from receiving events from this data table.
      Parameters:
      listener - the listener to remove from receiving events
    • getRecordClass

      public Class<? extends GenericRecord> getRecordClass()
      convenience method for user to detect record class
    • dataHandler

      public DataListener dataHandler() throws MissingPrimaryKeyException
      Handle reading and writing from a data adaptor
      Throws:
      MissingPrimaryKeyException
    • name

      public String name()
      Get the name of this table.
    • keys

      public Collection<String> keys()
      Get all keys for this table.
    • primaryKeys

      public Collection<String> primaryKeys()
      Get the primary keys for the table.
    • hasRecord

      public boolean hasRecord(GenericRecord genericRecord)
      Determine if this table contains the specified record
      Parameters:
      genericRecord - The record to test for membership in this table
      Returns:
      true if this table contains the record and false if not
    • add

      public void add(GenericRecord genericRecord) throws DataTable.AddRecordException
      Add the record to the table.
      Throws:
      DataTable.AddRecordException
    • remove

      public void remove(GenericRecord genericRecord)
      Remove the specified record from this table.
    • attributes

      public Collection<DataAttribute> attributes()
      Return the attributes of this table from the table's schema.
    • orderRecords

      public List<GenericRecord> orderRecords(Collection<GenericRecord> records, SortOrdering ordering)
      Order the records according to the specified sort ordering.
      Parameters:
      records - the records to sort.
      ordering - the sort ordering used to sort the records
      Returns:
      The records sorted by the sort ordering.
    • records

      public Collection<GenericRecord> records()
      Fetch all records held in the table
    • getRecords

      public List<GenericRecord> getRecords(SortOrdering ordering)
      Fetch all records held in the table and sort them according to the sort ordering.
      Parameters:
      ordering - The sort ordering used to sort the records.
      Returns:
      All of the records ordered according to the sort ordering.
    • genericRecord

      public <T> GenericRecord genericRecord(Map<String,T> bindings) throws DataTable.NonUniqueRecordException
      Fetch the record with matching key/value pair bindings. The keys must be one or more of the primary keys. If the record is not unique, an exception will be thrown.
      Throws:
      DataTable.NonUniqueRecordException
    • genericRecord

      public GenericRecord genericRecord(String key, Object value) throws DataTable.NonUniqueRecordException
      Fetch the record with a matching key/value pair binding. The key must be a primary key. If the record is not unique, an exception will be thrown.
      Throws:
      DataTable.NonUniqueRecordException
    • records

      public <T> Collection<GenericRecord> records(Map<String,T> bindings)
      Fetch the records with matching key/value pair bindings. The keys must be one or more of the primary keys.
      Parameters:
      bindings - The map of key/value pairs where the keys correspond to a subset of primary keys and the values are the ones we want to match.
      Returns:
      The matching records.
    • getRecords

      public <T> List<GenericRecord> getRecords(Map<String,T> bindings, SortOrdering ordering)
      Fetch the records with matching key/value pair bindings and sort them according to the sort ordering. The keys must be one or more of the primary keys.
      Parameters:
      bindings - The map of key/value pairs where the keys correspond to a subset of primary keys and the values are the ones we want to match.
      ordering - The sort ordering used to sort the records.
      Returns:
      The matching records sorted according to the ordering.
    • records

      public Collection<GenericRecord> records(String key, Object value)
      Fetch the records with a matching key/value pair binding. The key must be a primary key.
      Parameters:
      key - A primary key to fetch against.
      value - The value of the primary key to match.
      Returns:
      the matching records.
    • getRecords

      public List<GenericRecord> getRecords(String key, Object value, SortOrdering ordering)
      Fetch the records with a matching key/value pair binding and sort them according to the sort ordering. The key must be a primary key.
      Parameters:
      key - A primary key to fetch against.
      value - The value of the primary key to match.
      ordering - The sort ordering used to sort the records.
      Returns:
      The matching records sorted according to the ordering.
    • recordForNode

      public GenericRecord recordForNode(String nodeId) throws DataTable.NonUniqueRecordException
      Fetch the record with a matching nodeId. One of the primary keys must be "nodeId". If the record is not unique, an exception will be thrown.
      Throws:
      DataTable.NonUniqueRecordException
    • recordsForNode

      public Collection<GenericRecord> recordsForNode(String nodeId)
      Fetch the records with a matching nodeId. One of the primary keys must be "nodeId".
    • getUniquePrimaryKeyValues

      public final Collection<Object> getUniquePrimaryKeyValues(String key)
      Get the unique values of the specified primary key column.
      Parameters:
      key - The primary key column whose unique values we want to fetch.
      Returns:
      the unique values of the specified column.