de.erichseifert.gral.data
Class DataTable

java.lang.Object
  extended by de.erichseifert.gral.data.AbstractDataSource
      extended by de.erichseifert.gral.data.DataTable
All Implemented Interfaces:
DataSource, Iterable<Number>

public class DataTable
extends AbstractDataSource

Creates a DataTable object. DataTable is the basic implementation of DataSource. Implemented functionality includes:


Constructor Summary
DataTable(Class<? extends Number>... types)
          Creates a new DataTable object.
 
Method Summary
 void add(Collection<? extends Number> values)
          Adds a row with the specified container's elements to the table.
 void add(Number... values)
          Adds a row with the specified Number values to the table.
 void clear()
          Deletes all rows this table contains.
 Number get(int col, int row)
          Returns the row with the specified index.
 Class<? extends Number> getColumnClass(int col)
          Returns the data type of the specified column.
 int getColumnCount()
          Returns the number of columns of the data source.
 int getRowCount()
          Returns the number of rows of the data source.
 void remove(int row)
          Removes a specified row from the table.
 Number set(int col, int row, Number value)
          Sets the value of a certain cell.
 void sort(DataComparator... comparators)
          Sorts the table rows with the specified DataComparators.
 
Methods inherited from class de.erichseifert.gral.data.AbstractDataSource
addDataListener, getColumn, getRow, getStatistics, iterator, removeDataListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataTable

public DataTable(Class<? extends Number>... types)
Creates a new DataTable object.

Parameters:
types - type for each column
Method Detail

add

public void add(Number... values)
Adds a row with the specified Number values to the table. The values are added in the order they are specified. If the types of the table columns and the values do not match, an exception is thrown.

Parameters:
values - values to be added as a row
Throws:
IllegalArgumentException - if the type of the table columns and the type of the values that should be added do not match

add

public void add(Collection<? extends Number> values)
Adds a row with the specified container's elements to the table. The values are added in the order they are specified. If the types of the table columns and the values do not match, an exception is thrown.

Parameters:
values - values to be added as a row
Throws:
IllegalArgumentException - if the type of the table columns and the type of the values that should be added do not match

remove

public void remove(int row)
Removes a specified row from the table.

Parameters:
row - Index of the row to remove

clear

public void clear()
Deletes all rows this table contains.


get

public Number get(int col,
                  int row)
Description copied from interface: DataSource
Returns the row with the specified index.

Parameters:
col - index of the column to return
row - index of the row to return
Returns:
the specified value of the data cell

set

public Number set(int col,
                  int row,
                  Number value)
Sets the value of a certain cell.

Parameters:
col - Column of the cell to change.
row - Row of the cell to change.
value - New value to be set.
Returns:
Old value that was replaced.

getRowCount

public int getRowCount()
Description copied from interface: DataSource
Returns the number of rows of the data source.

Returns:
number of rows in the data source.

getColumnCount

public int getColumnCount()
Description copied from interface: DataSource
Returns the number of columns of the data source.

Returns:
number of columns in the data source.

getColumnClass

public Class<? extends Number> getColumnClass(int col)
Returns the data type of the specified column.

Parameters:
col - Column.
Returns:
Data type.

sort

public void sort(DataComparator... comparators)
Sorts the table rows with the specified DataComparators. The row values are compared in the way the comparators are specified.

Parameters:
comparators - comparators used for sorting


Copyright © 2009-2010. All Rights Reserved.