Class RamAttributeStore

All Implemented Interfaces:
EditableTableModel, PopupActivationListener, Serializable, Comparable, EventListener, ListSelectionListener, TableModel
Direct Known Subclasses:
CategoryTable, ExcelStore, SummaryTable, SummaryTable.Snapshot

public class RamAttributeStore extends AttributeStore implements EditableTableModel
This class holds an in-memory AttributeStore. There are methods for adding, rearanging and removing rows. The method for adding rows must be overriden to create the appropriate values for each column.

This class has constructors to intitialze the table fron an existing table, or to construct an empty table with a specified set of columns.

There are also static methods to create summary tables from other tables.

See Also:
Serialized Form
  • Constructor Details

    • RamAttributeStore

      public RamAttributeStore(AttributeStore as)
      Construct the in-memory data store from another AttributeStore. The resulting table will be identical to the original, but with all data cached in ram. This may result in substantial performance gains in some situations, but may require large amounts of ram for large tables.
      Parameters:
      as - the AttributeStore to copy.
    • RamAttributeStore

      public RamAttributeStore(AttributeStore as, AttributeFormat[] extra)
      Construct the in-memory data store from another AttributeStore, including extra columns. The resulting table will be similar to the original, but with all data cached in ram and extra columns added at the end. This may result in substantial performance gains in some situations, but may require large amounts of ram for large tables.
      Parameters:
      as - the AttributeStore to copy.
      extra - the list of extra columns to add on to the end of the table.
    • RamAttributeStore

      public RamAttributeStore(AttributeFormat[] f, Object[][] cache)
      Construct a new RamAttributeStore. The column definitions are as sepcified, and the table is backed by the data in the cache that is provided.
      Parameters:
      f - The list of column spcifications
      cache - The array of data for the initial rows ans columns in this table.
    • RamAttributeStore

      public RamAttributeStore(AttributeFormat[] f, Object[][][] cache, int[] yearsForPeriod)
      Construct a new RamAttributeStore. The column definitions are as sepcified, and the table is backed by the data in the cache that is provided.
      Parameters:
      f - The list of column spcifications
      cache - The array of data for the initial rows ans columns in this table.
  • Method Details

    • getRowCount

      public int getRowCount()
      Description copied from class: AttributeStore
      Get the number of rows in this store
      Specified by:
      getRowCount in interface TableModel
      Specified by:
      getRowCount in class AttributeStore
      Returns:
      the number of rows in this store
    • getPeriodCount

      public int getPeriodCount()
      Description copied from class: AttributeStore
      Get the total number of periods that this store supports
      Specified by:
      getPeriodCount in class AttributeStore
      Returns:
      The number of periods in this store
    • getYearForPeriod

      public int getYearForPeriod(int period)
      Description copied from class: AttributeStore
      Get the ending year for a given period.
      Specified by:
      getYearForPeriod in class AttributeStore
      Parameters:
      period - The period of interest
      Returns:
      the year for a given period
    • clearAllRows

      public void clearAllRows()
      Remove all rows from this table
    • getCache

      public Object[][][] getCache()
      Return a reference to the underlying data for this table
    • getValueAt

      public Object getValueAt(int row, int column, int period)
      Description copied from class: AttributeStore
      Get a cell value
      Specified by:
      getValueAt in class AttributeStore
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      period - The period of interest
      Returns:
      An object containing the cell value.
    • setValueAt

      public void setValueAt(Object object, int row, int column, int period)
      Description copied from class: AttributeStore
      Set the value in a cell and notify listeners that the value has changed.

      Implementing classes that override must call this method to ensure that joins are properly maintained.

      Overrides:
      setValueAt in class AttributeStore
      Parameters:
      object - The value to be set.
      row - The row containing the cell
      column - The column containing the cell
      period - The period of interest
    • insertRow

      public void insertRow(Object[] rowData, int pos)
      Insert a row of data at a given position in the table. The position must be a valid row number between 0 and the number of rows in the table.
      Parameters:
      rowData - an array containg the data to add
      pos - the row position to add the data at
    • insertRows

      public void insertRows(Object[][] rowData, int pos)
      Insert multiple rows of data at a given position in the table. The position must be a valid row number between 0 and the number of rows in the table.
      Parameters:
      rowData - an array of arrays containg the rows to add
      pos - the row position to add the data at
    • addRow

      public void addRow(Object[] rowData)
      Add a row of data to the end of the table.
      Specified by:
      addRow in interface EditableTableModel
      Parameters:
      rowData - an array containg the data to add
    • addRows

      public void addRows(Object[][] rowData)
      Add multiple rows of data to the end of the table.
      Parameters:
      rowData - an array of arrays containg the rows to add
    • addRow

      public void addRow(Component parent)
      Add a row of data to the table using an interactive query. This method must be overridden to provide the interface to fill in the data.
      Specified by:
      addRow in interface EditableTableModel
    • removeRow

      public void removeRow(int row)
      Remove the row specified by the row number.
      Specified by:
      removeRow in interface EditableTableModel
    • moveRow

      public void moveRow(int from, int to)
      Description copied from interface: EditableTableModel
      Move the specified row to a new location
      Specified by:
      moveRow in interface EditableTableModel
    • createSummaryTable

      public static AttributeStore createSummaryTable(AttributeStore as, String cat, String val, int period, Observer obs) throws Exception
      Create a summary table. The summary table will have one row for each unique value of the category expression. The row will contain the category expression and the sum of the value expression for each matching record. Only records that are selected in the base table will be included in the summary table.

      This method is equivalent to:

       RamAttributeStore.createSummaryTable(as, cat, val, "selected()", 
          period, obs);
       
      Parameters:
      as - The input attribute store to be summarized
      cat - The category expression. The output table will have one row for each unique value of the catgory expression.
      val - The value expression. The output table will sum the value expression for each unique category.
      period - The period to summarize
      obs - An optional Observer object to track the progress of the summary. This parameter may be null.
      Returns:
      Will return an RamAttributeStore with the results of the summary. This table will have two columns ('Category' and 'Value') and one row for each of the unique categories.
      Throws:
      Exception
    • createSummaryTable

      @Deprecated public static AttributeStore createSummaryTable(AttributeStore as, String cat, String val, String select, int period, Observer obs) throws Exception
      Deprecated.
      Create a summary table. The summary table will have one row for each unique value of the category expression. The row will contain the category expression and the sum of the value expression for each matching record. Only records that match the select expression will be included in the summary table.
      Parameters:
      as - The input attribute store to be summarized
      cat - The category expression. The output table will have one row for each unique value of the catgory expression.
      val - The value expression. The output table will sum the value expression for each unique category.
      select - The selection expression. Only records matching this boolean expression will be included in the summary.
      period - The period to summarize
      obs - An optional Observer object to track the progress of the summary. This parameter may be null.
      Returns:
      Will return an RamAttributeStore with the results of the summary. This table will have two columns ('Category' and 'Value') and one row for each of the unique categories.
      Throws:
      Exception