TissueInfo API 20091124110011

edu.mssm.crover.tables
Class ArrayTable

java.lang.Object
  extended by edu.mssm.crover.tables.ArrayTable
All Implemented Interfaces:
Table

public class ArrayTable
extends Object
implements Table

Array-based implementation of the Table interface. The array is reallocated each time a need to grow the allocated space is encountered. That is not so smart as this is reasonable only for small tables: at reallocation time, twice the storage space of a column is used during the copy.


Nested Class Summary
 class ArrayTable.ColumnDescription
          Holds and describes a column of this table.
 class ArrayTable.RowIterator
           
 
Field Summary
protected  int chunk
           
protected  int INITIAL_LENGTH
           
 
Constructor Summary
ArrayTable()
           
 
Method Summary
 int addColumn(String identifier, Class type)
          Adds a new column to this table.
 void appendBooleanValue(int column, boolean value)
          Appends a boolean value to the specified column.
 void appendBooleanValue(int column, int row, boolean value)
          Appends a boolean value to the specified column, on the specified row.
 void appendCharValue(int column, char value)
          Appends a char value to the specified column.
 void appendCharValue(int column, int row, char value)
          Appends a char value to the specified column on the specified row.
 void appendDoubleValue(int column, double value)
          Appends a double value to the specified column.
 void appendDoubleValue(int column, int row, double value)
          Appends a double value to the specified column on the specified row.
 void appendFloatValue(int column, float value)
          Appends a float value to the specified column.
 void appendFloatValue(int column, int row, float value)
          Appends a float value to the specified column on the specified row.
 void appendIntValue(int column, int value)
          Appends an int value to the specified column.
 void appendIntValue(int column, int row, int value)
          Appends an int value to the specified column, on the specified row.
 void appendObject(int column, int row, Object value)
          Appends a Object value to the specified column on the specified row.
 void appendObject(int column, Object value)
          Appends a Object value to the specified column.
 void checkSize(int column)
          Check wether the internal storage needs to be expanded, performs the required reallocation when it does.
 void clean()
          Cleans this column.
 Table copy()
           
 void copy(int sourceColumn, Table.RowIterator source, int destColumn, Table.RowIterator dest)
          Copy the value at position (column, source) to the position (column, dest).
 Table copy(RowFilter filter)
           
 Table copy(RowFilter rowFilter, ColumnFilter columnFilter)
           
 void copy(Table sourceTable, int sourceColumn, Table.RowIterator source, Table destTable, int destColumn, Table.RowIterator dest)
          Copy the value at position sourceTable(column, source) to the position destTable(column, dest).
 void defineColumnsFrom(Table t)
          Defines the columns of this table from the columns in source.
 void defineColumnsFrom(Table t, ColumnFilter columnFilter)
          Defines the columns of this table from the columns in source.
 String elementToString(int column, Table.RowIterator row)
           
 boolean equals(Object obj)
          Compare this ArrayTable with another table.
 Table.RowIterator firstRow()
          Returns an iterator that reference the first instance of this table.
protected  void fixRowNumber(int columnRowNumber)
          Enforce the number of row of the table to be at least equal to the provided number of element of the column.
 boolean getBooleanValue(int column, Table.RowIterator row)
          Returns the value stored in this position as an boolean, when appropriate.
 char getCharValue(int column, Table.RowIterator row)
          Returns the value stored in this position as an int, when appropriate.
 int getColumnIndex(String identifier)
          Returns the column index associated with this identifier.
 int getColumnIndexOrDefault(String identifier)
          Returns the column index associated with this identifier, or -1 if the column does not exist.
 int getColumnNumber()
          Returns the number of columns of this table.
 ArrayTable.ColumnDescription getColumnValues(int i)
           
 double[] getDoubles(String identifier)
          Get the doubles for a particular column id.
 double getDoubleValue(int column, Table.RowIterator row)
          Returns the value stored in this position as an double, when appropriate.
 float getFloatValue(int column, Table.RowIterator row)
          Returns the value stored in this position as a float, when appropriate.
 String getIdentifier(int column)
          Returns the identifier associated with this column index.
 int getIntValue(int column, Table.RowIterator row)
          Returns the value stored in this position as an int, when appropriate.
 int getRowNumber()
          Returns the number of rows of this table.
 String[] getStrings(String identifier)
          Get athe array of strings for a particular column id.
 Class<?> getType(int column)
          Returns the type of the column which index is passed as argument.
 Object getValue(int column, Table.RowIterator row)
          Returns the value stored in this position as an Object, when appropriate.
 void incrementRowNumber()
           
 boolean isColumn(String identifier)
          Returns true when the identifier designate a column of this column.
 Table.RowIterator lastRow()
          Returns an iterator that reference the last instance of this table.
 void parseAppend(int column, String value)
          Append a value passed as a String.
 boolean permutateColumns(String columnName, int newColumnPosition)
          Permutate the position of columns.
 void processRows(RowProcessor myRowProcessor)
          Process each row of this table with user-defineable operation.
 void removeColumn(int columnIndex)
          Removes a column from this table.
 void removeColumn(String identifier)
          Removes a column from this table.
 void removeLastRow()
          Removes the last appended row from each column of this table.
 void reserve(int column, int numElements)
          Reserve the space for numElements in the given column.
 void setChunk(int chunk)
          Set the number of element of a column to expand the size with when the available space is saturated for this column.
 void setInitialSize(int init)
          The amount of element initially available for each column before a reallocation is required.
 void setValue(int columnIndex, Table.RowIterator ri, boolean value)
           
 void setValue(int columnIndex, Table.RowIterator ri, char value)
           
 void setValue(int columnIndex, Table.RowIterator ri, double value)
           
 void setValue(int columnIndex, Table.RowIterator ri, float value)
           
 void setValue(int columnIndex, Table.RowIterator ri, int value)
           
 void setValue(int columnIndex, Table.RowIterator ri, long value)
           
 String toString()
           
 String toString(Table source)
          Returns a text representation of the table source.
 String toString(Table source, boolean printData)
          Returns a text representation of the table source.
 Table transpose(DefineColumnFromRow columnHelper)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

chunk

protected int chunk

INITIAL_LENGTH

protected int INITIAL_LENGTH
Constructor Detail

ArrayTable

public ArrayTable()
Method Detail

copy

public Table copy()
           throws TypeMismatchException,
                  InvalidColumnException
Specified by:
copy in interface Table
Throws:
TypeMismatchException
InvalidColumnException

copy

public Table copy(RowFilter filter)
           throws TypeMismatchException,
                  InvalidColumnException
Specified by:
copy in interface Table
Throws:
TypeMismatchException
InvalidColumnException

copy

public Table copy(RowFilter rowFilter,
                  ColumnFilter columnFilter)
           throws TypeMismatchException,
                  InvalidColumnException
Specified by:
copy in interface Table
Throws:
TypeMismatchException
InvalidColumnException

transpose

public Table transpose(DefineColumnFromRow columnHelper)
                throws InvalidColumnException,
                       TypeMismatchException,
                       ColumnTypeException
Specified by:
transpose in interface Table
Throws:
InvalidColumnException
TypeMismatchException
ColumnTypeException

permutateColumns

public boolean permutateColumns(String columnName,
                                int newColumnPosition)
                         throws InvalidColumnException
Permutate the position of columns. The named column will be moved to position.

Specified by:
permutateColumns in interface Table
Parameters:
columnName - The name of the column to move
newColumnPosition - the position to place the column
Returns:
True if a permutation was necessary. False otherwise.
Throws:
InvalidColumnException - if the column name or position is not valid

getStrings

public String[] getStrings(String identifier)
                    throws InvalidColumnException
Get athe array of strings for a particular column id.

Specified by:
getStrings in interface Table
Parameters:
identifier - The column identifier to get the strings for
Returns:
an array of strings (possibly empty)
Throws:
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

getDoubles

public double[] getDoubles(String identifier)
                    throws InvalidColumnException
Get the doubles for a particular column id.

Specified by:
getDoubles in interface Table
Parameters:
identifier - The column id to get the values for
Returns:
an array of doubles
Throws:
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

getColumnValues

public ArrayTable.ColumnDescription getColumnValues(int i)
Specified by:
getColumnValues in interface Table

setValue

public final void setValue(int columnIndex,
                           Table.RowIterator ri,
                           int value)
Specified by:
setValue in interface Table

setValue

public final void setValue(int columnIndex,
                           Table.RowIterator ri,
                           long value)
Specified by:
setValue in interface Table

setValue

public final void setValue(int columnIndex,
                           Table.RowIterator ri,
                           boolean value)
Specified by:
setValue in interface Table

setValue

public final void setValue(int columnIndex,
                           Table.RowIterator ri,
                           float value)
Specified by:
setValue in interface Table

setValue

public final void setValue(int columnIndex,
                           Table.RowIterator ri,
                           double value)
Specified by:
setValue in interface Table

setValue

public final void setValue(int columnIndex,
                           Table.RowIterator ri,
                           char value)
Specified by:
setValue in interface Table

clean

public void clean()
Cleans this column. Remove all rows. Other column definitions are kept.


processRows

public void processRows(RowProcessor myRowProcessor)
                 throws TypeMismatchException,
                        InvalidColumnException
Process each row of this table with user-defineable operation.

Specified by:
processRows in interface Table
Parameters:
myRowProcessor - The operation to apply to each row of this table.
Throws:
TypeMismatchException
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

copy

public final void copy(Table sourceTable,
                       int sourceColumn,
                       Table.RowIterator source,
                       Table destTable,
                       int destColumn,
                       Table.RowIterator dest)
Copy the value at position sourceTable(column, source) to the position destTable(column, dest). The previous value, (column, dest), is overridden.

Specified by:
copy in interface Table

copy

public final void copy(int sourceColumn,
                       Table.RowIterator source,
                       int destColumn,
                       Table.RowIterator dest)
Copy the value at position (column, source) to the position (column, dest). The previous value, (column, dest), is overridden. The operation is performed on this table.

Specified by:
copy in interface Table

reserve

public void reserve(int column,
                    int numElements)
Reserve the space for numElements in the given column. Required before copying the elements from a different table.

Specified by:
reserve in interface Table

addColumn

public int addColumn(String identifier,
                     Class type)
Adds a new column to this table.

Specified by:
addColumn in interface Table
Parameters:
identifier - The name of the new column
type - The type of the new column
Returns:
The index of this column.

removeColumn

public void removeColumn(String identifier)
                  throws InvalidColumnException
Removes a column from this table.

Specified by:
removeColumn in interface Table
Parameters:
identifier - The identifer for the column to remove
Throws:
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

removeColumn

public void removeColumn(int columnIndex)
Description copied from interface: Table
Removes a column from this table.

Specified by:
removeColumn in interface Table
Parameters:
columnIndex - Index of the column to remove.

isColumn

public final boolean isColumn(String identifier)
Returns true when the identifier designate a column of this column.

Specified by:
isColumn in interface Table

fixRowNumber

protected void fixRowNumber(int columnRowNumber)
Enforce the number of row of the table to be at least equal to the provided number of element of the column.


incrementRowNumber

public void incrementRowNumber()
Specified by:
incrementRowNumber in interface Table

getColumnNumber

public final int getColumnNumber()
Returns the number of columns of this table.

Specified by:
getColumnNumber in interface Table
Returns:
the number of columns in this table

getRowNumber

public final int getRowNumber()
Returns the number of rows of this table.

Specified by:
getRowNumber in interface Table
Returns:
the number of rows in this table

getIdentifier

public final String getIdentifier(int column)
Returns the identifier associated with this column index.

Specified by:
getIdentifier in interface Table

getColumnIndex

public final int getColumnIndex(String identifier)
                         throws InvalidColumnException
Returns the column index associated with this identifier.

Specified by:
getColumnIndex in interface Table
Parameters:
identifier - The name of the column to get the index for
Returns:
The index of the specified column
Throws:
InvalidColumnException - if the identifier is not part of this column

getColumnIndexOrDefault

public final int getColumnIndexOrDefault(String identifier)
Returns the column index associated with this identifier, or -1 if the column does not exist.

Parameters:
identifier - column identifier.
Returns:
index of the column, or -1 if the column is not defined.

getType

public Class<?> getType(int column)
Returns the type of the column which index is passed as argument.

Specified by:
getType in interface Table

firstRow

public Table.RowIterator firstRow()
Returns an iterator that reference the first instance of this table.

Specified by:
firstRow in interface Table

lastRow

public Table.RowIterator lastRow()
Returns an iterator that reference the last instance of this table.

Specified by:
lastRow in interface Table

getIntValue

public int getIntValue(int column,
                       Table.RowIterator row)
                throws TypeMismatchException,
                       InvalidColumnException
Returns the value stored in this position as an int, when appropriate.

Specified by:
getIntValue in interface Table
Throws:
TypeMismatchException - Thrown when the element is not an integer.
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

getCharValue

public char getCharValue(int column,
                         Table.RowIterator row)
                  throws TypeMismatchException,
                         InvalidColumnException
Returns the value stored in this position as an int, when appropriate.

Specified by:
getCharValue in interface Table
Throws:
TypeMismatchException - Thrown when the element is not an integer.
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

getBooleanValue

public boolean getBooleanValue(int column,
                               Table.RowIterator row)
                        throws TypeMismatchException
Returns the value stored in this position as an boolean, when appropriate.

Specified by:
getBooleanValue in interface Table
Throws:
TypeMismatchException - Thrown when the element is not a boolean.

getDoubleValue

public double getDoubleValue(int column,
                             Table.RowIterator row)
                      throws TypeMismatchException
Returns the value stored in this position as an double, when appropriate.

Specified by:
getDoubleValue in interface Table
Throws:
TypeMismatchException - Thrown when the element is not a double.

appendIntValue

public void appendIntValue(int column,
                           int value)
                    throws TypeMismatchException
Appends an int value to the specified column. Table are write once data storage. At least at the moment.

Specified by:
appendIntValue in interface Table
Throws:
TypeMismatchException - Thrown when the column exists but its type is incompatible with an int.

appendIntValue

public void appendIntValue(int column,
                           int row,
                           int value)
                    throws TypeMismatchException
Appends an int value to the specified column, on the specified row. Table are write once data storage. At least at the moment.

Throws:
TypeMismatchException

appendBooleanValue

public final void appendBooleanValue(int column,
                                     boolean value)
Appends a boolean value to the specified column. Table are write once data storage. At least at the moment.

Specified by:
appendBooleanValue in interface Table

appendBooleanValue

public final void appendBooleanValue(int column,
                                     int row,
                                     boolean value)
Appends a boolean value to the specified column, on the specified row. Table are write once data storage. At least at the moment.


appendCharValue

public final void appendCharValue(int column,
                                  char value)
Appends a char value to the specified column.

Specified by:
appendCharValue in interface Table

appendCharValue

public final void appendCharValue(int column,
                                  int row,
                                  char value)
Appends a char value to the specified column on the specified row.


appendObject

public final void appendObject(int column,
                               Object value)
Appends a Object value to the specified column.

Specified by:
appendObject in interface Table

appendObject

public final void appendObject(int column,
                               int row,
                               Object value)
Appends a Object value to the specified column on the specified row.


appendFloatValue

public final void appendFloatValue(int column,
                                   float value)
                            throws TypeMismatchException
Appends a float value to the specified column.

Specified by:
appendFloatValue in interface Table
Throws:
TypeMismatchException

appendFloatValue

public final void appendFloatValue(int column,
                                   int row,
                                   float value)
                            throws TypeMismatchException
Appends a float value to the specified column on the specified row.

Throws:
TypeMismatchException

appendDoubleValue

public final void appendDoubleValue(int column,
                                    double value)
                             throws TypeMismatchException
Appends a double value to the specified column.

Specified by:
appendDoubleValue in interface Table
Throws:
TypeMismatchException

appendDoubleValue

public final void appendDoubleValue(int column,
                                    int row,
                                    double value)
                             throws TypeMismatchException
Appends a double value to the specified column on the specified row.

Throws:
TypeMismatchException

parseAppend

public final void parseAppend(int column,
                              String value)
                       throws ColumnTypeException
Append a value passed as a String. This operation imply parsing the value from its String representation. This is supported for the following types: int, float, boolean, String, and for any object type when a StringAppender has been provided when the column has been created.

Specified by:
parseAppend in interface Table
Throws:
ColumnTypeException
See Also:
StringAppender

setChunk

public void setChunk(int chunk)
Set the number of element of a column to expand the size with when the available space is saturated for this column. This implementation uses an array than is copied onto a larger one each time the array is full and new elements. As a programmer, you want to minimize the occurence of such events are they spoil memory and CPU. If you know that you are going to add 10M rows to the table, you may consider setting the chunk to 10M, so that the reallocation will occur only once, when the table hold a few elements. This method is also useful fot testing purposes, when one whant to check that the behaviour is correct at reallocation time (use low values of chunk and initialSize). The default is 10000.


setInitialSize

public void setInitialSize(int init)
The amount of element initially available for each column before a reallocation is required. If you know that you are going to add 10M rows to the table, you may consider setting the initial size to 10M+1, preventing the reallocation to ever occur. The default value is 1000.


checkSize

public final void checkSize(int column)
Check wether the internal storage needs to be expanded, performs the required reallocation when it does.


getValue

public Object getValue(int column,
                       Table.RowIterator row)
                throws TypeMismatchException,
                       InvalidColumnException
Returns the value stored in this position as an Object, when appropriate.

Specified by:
getValue in interface Table
Throws:
TypeMismatchException - Thrown when the element is not a subclass of Object
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

getFloatValue

public float getFloatValue(int column,
                           Table.RowIterator row)
                    throws TypeMismatchException,
                           InvalidColumnException
Returns the value stored in this position as a float, when appropriate.

Specified by:
getFloatValue in interface Table
Throws:
TypeMismatchException - Thrown when the element is not a float.
InvalidColumnException - Thrown when the specified index does not identify a column of this table (negative indices and indices greater than getColumnNumber() throw this exception).

elementToString

public String elementToString(int column,
                              Table.RowIterator row)
Specified by:
elementToString in interface Table

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(Table source)
Returns a text representation of the table source.

Specified by:
toString in interface Table

toString

public String toString(Table source,
                       boolean printData)
Returns a text representation of the table source.

Specified by:
toString in interface Table

defineColumnsFrom

public void defineColumnsFrom(Table t)
Defines the columns of this table from the columns in source. For each column of the source table, a new column is added to this Table.

Specified by:
defineColumnsFrom in interface Table
Parameters:
t - Source for the column definition.

defineColumnsFrom

public void defineColumnsFrom(Table t,
                              ColumnFilter columnFilter)
Defines the columns of this table from the columns in source. For each column of the source table, a new column is added to this Table.

Parameters:
t - Source for the column definition.

removeLastRow

public void removeLastRow()
Removes the last appended row from each column of this table.

Specified by:
removeLastRow in interface Table

equals

public boolean equals(Object obj)
Compare this ArrayTable with another table. True from this means it has the same number of columns, same column identifiers, and the data within each of the columns is identical and in the same order.

Overrides:
equals in class Object
Parameters:
obj - objec to compare this ArrayTable to.
Returns:
true of the tables are the same.

TissueInfo API 20091124110011

Copyright © 2001-2009 Institute for Computational Biomedicine, All Rights Reserved.