## nom.tam.util
Class ColumnTable

    java.lang.Object
      nom.tam.util.ColumnTable

All Implemented Interfaces:
  DataTable

public class ColumnTable
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.

Constructor Summary
`ColumnTable(Object[] arrays, int[] sizes)` Create the object after checking consistency.

Method Summary
`protected void` `checkArrayConsistency(Object[] arrays, int[] sizes)` Check that the columns and sizes are consistent.
`Class[]` `getBases()` Get the base classes of the columns.
`Object` `getColumn(int col)` Get a particular column.
`Object` `getElement(int row, int col)` Get a element of the table.
`int` `getNcol()` Get the number of columns in the table.
`int` `getNrow()` Get the number of rows in the table.
`protected void` `getNumberOfRows()` Calculate the number of rows to read/write at a time.
`Object` `getRow(int row)` Get a row of data.
`char[]` `getTypes()` Get the characters describing the base classes of the columns.
`protected void` `initializePointers()` Set the pointer arrays for the eight primitive types to point to the appropriate elements of arrays.
`int` `read(InputStream is)` Read a table.
`void` `setColumn(int col, Object newColumn)` Set the values in a particular column.
`void` `setElement(int row, int col, Object x)` Modify an element of the table.
`void` `setRow(int row, Object x)` Modify a row of data.
`protected void` `setup(Object[] arrays, int[] sizes)` Actually perform the initialization.
`int` `write(OutputStream os)` Write a table.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### 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

Method Detail

### setup

    protected void setup(Object[] arrays,
                         int[] sizes)
                  throws TableException

  Actually perform the initialization.

  Throws:
    `TableException`

### getNrow

    public int getNrow()

  Get the number of rows in the table.

  Specified by:
    `getNrow` in interface `DataTable`

### getNcol

    public int getNcol()

  Get the number of columns in the table.

  Specified by:
    `getNcol` in interface `DataTable`

### 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.

### 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 informaiton in the table.

### 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.

### 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.

### getRow

    public Object getRow(int row)

  Get a row of data.

  Specified by:
    `getRow` in interface `DataTable`
  Returns:
    An array of objects each containing a primitive array.

### 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.,
  Throws:
    `TableException`
  See Also:
    `ColumnTable.getColumn.`

### checkArrayConsistency

    protected void checkArrayConsistency(Object[] arrays,
                                         int[] sizes)
                                  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:
    `arrays` - The arrays defining the columns.
    `sizes` - The number of elements in each row for the column.
  Throws:
    `TableException`

### getNumberOfRows

    protected void getNumberOfRows()

  Calculate the number of rows to read/write at a time.

### initializePointers

    protected void initializePointers()

  Set the pointer arrays for the eight primitive types to point to the appropriate elements of arrays.

### read

    public int read(InputStream is)
             throws IOException

  Read a table.

  Parameters:
    `is` - The input stream to read from.
  Throws:
    `IOException`

### write

    public int write(OutputStream os)
              throws IOException

  Write a table.

  Parameters:
    `os` - the output stream to write to.
  Throws:
    `IOException`

### getBases

    public Class[] getBases()

  Get the base classes of the columns.

  Returns:
    An array of Class objects, one for each column.

### getTypes

    public char[] getTypes()

  Get the characters describing the base classes of the columns.

  Returns:
    An array of char's, one for each column.