Package nom.tam.util

Class ColumnTable<T>

java.lang.Object
nom.tam.util.ColumnTable<T>
All Implemented Interfaces:
DataTable

public class ColumnTable<T> extends Object implements DataTable
A data table is conventionally considered to consist of rows and columns, where the structure within each column is constant, but different columns may have different structures. I.e., structurally columns may differ but rows are identical. Typically tabular data is usually stored in row order which can make it extremely difficult to access efficiently using Java. This class provides efficient access to data which is stored in row order and allows users to get and set the elements of the table. The table can consist only of arrays of primitive types. Data stored in column order can be efficiently read and written using the BufferedDataXputStream classes. The table is represented entirely as a set of one-dimensional primitive arrays. For a given column, a row consists of some number of contiguous elements of the array. Each column is required to have the same number of rows. Information regarding the dimensionality of columns and possible data pointers is retained for use by clients which can understand them.
  • Constructor Details

    • ColumnTable

      public ColumnTable(Object[] arrays, int[] sizes) throws TableException
      Create the object after checking consistency.
      Parameters:
      arrays - An array of one-d primitive arrays.
      sizes - The number of elements in each row for the corresponding column
      Throws:
      TableException - if the structure of the columns is not consistent
  • Method Details

    • addColumn

      public void addColumn(Object newColumn, int size) throws TableException
      Add a column .
      Parameters:
      newColumn - the column to add.
      size - size for the column
      Throws:
      TableException - if the structure of the new column does not fit the structure of the rows/columns
    • addPointer

      protected void addPointer(Object data) throws TableException
      Add a pointer in the pointer lists.
      Parameters:
      data - data pointer to add
      Throws:
      TableException - if the structure of the specified array does not fit the structure of the rows/columns
    • addRow

      public void addRow(Object[] row) throws TableException
      Add a row to the table. This method is very inefficient for adding multiple rows and should be avoided if possible.
      Parameters:
      row - the row to add
      Throws:
      TableException - if the structure of the specified array does not fit the structure of the rows/columns
    • checkArrayConsistency

      protected void checkArrayConsistency(Object[] newArrays, int[] newSizes) throws TableException
      Check that the columns and sizes are consistent. Inconsistencies include:
      • arrays and sizes have different lengths.
      • an element of arrays is not a primitive array.
      • the size of an array is not divisible by the sizes entry.
      • the number of rows differs for the columns.
      Parameters:
      newArrays - The arrays defining the columns.
      newSizes - The number of elements in each row for the column.
      Throws:
      TableException - if the table was inconsistent
    • copy

      public ColumnTable<T> copy() throws TableException
      Throws:
      TableException
    • deleteColumns

      public void deleteColumns(int start, int len) throws TableException
      Delete a contiguous set of columns from the table.
      Parameters:
      start - The first column (0-indexed) to be deleted.
      len - The number of columns to be deleted.
      Throws:
      TableException - if the request goes outside the boundaries of the table or if the length is negative.
    • deleteRow

      public void deleteRow(int row) throws TableException
      Delete a row from the table.
      Parameters:
      row - The row (0-indexed) to be deleted.
      Throws:
      TableException - if the request goes outside the boundaries of the table or if the length is negative.
    • deleteRows

      public void deleteRows(int row, int length) throws TableException
      Delete a contiguous set of rows from the table.
      Parameters:
      row - The row (0-indexed) to be deleted.
      length - The number of rows to be deleted.
      Throws:
      TableException - if the request goes outside the boundaries of the table or if the length is negative.
    • getBases

      public Class<?>[] getBases()
      Get the base classes of the columns.
      Returns:
      An array of Class objects, one for each column.
    • getColumn

      public Object getColumn(int col)
      Get a particular column.
      Specified by:
      getColumn in interface DataTable
      Parameters:
      col - The column desired.
      Returns:
      an object containing the column data desired. This will be an instance of a 1-d primitive array.
    • getColumns

      public Object[] getColumns()
      Returns:
      the actual data arrays
    • getElement

      public Object getElement(int row, int col)
      Get a element of the table.
      Specified by:
      getElement in interface DataTable
      Parameters:
      row - The row desired.
      col - The column desired.
      Returns:
      A primitive array containing the information. Note that an array will be returned even if the element is a scalar.
    • getExtraState

      public T getExtraState()
      Returns:
      the pointer state
    • getNCols

      public int getNCols()
      Get the number of columns in the table.
      Specified by:
      getNCols in interface DataTable
    • getNRows

      public int getNRows()
      Get the number of rows in the table.
      Specified by:
      getNRows in interface DataTable
    • getRow

      public Object getRow(int row)
      Get a row of data.
      Specified by:
      getRow in interface DataTable
      Parameters:
      row - The row desired.
      Returns:
      An array of objects each containing a primitive array.
    • getSizes

      public int[] getSizes()
    • getTypes

      public char[] getTypes()
      Get the characters describing the base classes of the columns.
      Returns:
      An array of char's, one for each column.
    • initializePointers

      protected void initializePointers()
      Set the pointer arrays for the eight primitive types to point to the appropriate elements of arrays.
    • read

      public void read(ArrayDataInput is) throws IOException
      Read a table.
      Parameters:
      is - The input stream to read from.
      Throws:
      IOException - if the reading failed
    • setColumn

      public void setColumn(int col, Object newColumn) throws TableException
      Set the values in a particular column. The new values must match the old in length but not necessarily in type.
      Specified by:
      setColumn in interface DataTable
      Parameters:
      col - The column to modify.
      newColumn - The new column data. This should be a primitive array.
      Throws:
      TableException - Thrown when the new data is not commenserable with information in the table.
    • setElement

      public void setElement(int row, int col, Object x) throws TableException
      Modify an element of the table.
      Specified by:
      setElement in interface DataTable
      Parameters:
      row - The row containing the element.
      col - The column containing the element.
      x - The new datum. This should be 1-d primitive array.
      Throws:
      TableException - Thrown when the new data is not of the same type as the data it replaces.
    • setExtraState

      public void setExtraState(T opaque)
      Store additional information that may be needed by the client to regenerate initial arrays.
      Parameters:
      opaque - the extra state to set.
    • setRow

      public void setRow(int row, Object x) throws TableException
      Modify a row of data.
      Specified by:
      setRow in interface DataTable
      Parameters:
      row - The row to be modified.
      x - The data to be modified. This should be an array of objects. It is described as an Object here since other table implementations may use other methods to store the data (e.g., @see nom.tam.util.ColumnTable)
      Throws:
      TableException
    • write

      public void write(ArrayDataOutput os) throws IOException
      Write a table.
      Parameters:
      os - the output stream to write to.
      Throws:
      IOException - if the write operation failed
    • write

      public void write(ArrayDataOutput os, int rowStart, int rowEnd, int columnNr) throws IOException
      Write a column of a table.
      Parameters:
      os - the output stream to write to.
      rowStart - first row to write
      rowEnd - row number that should not be written anymore
      columnNr - zero based column number to write.
      Throws:
      IOException - if the write operation failed
    • read

      public void read(ArrayDataInput is, int rowStart, int rowEnd, int columnNr) throws IOException
      Read a column of a table.
      Parameters:
      is - The input stream to read from.
      rowStart - first row to read
      rowEnd - row number that should not be read anymore
      columnNr - the columnNumber to read.
      Throws:
      IOException - if the reading failed