de.erichseifert.gral.data
Class DataTable
- java.lang.Object
-
- de.erichseifert.gral.data.AbstractDataSource
-
- de.erichseifert.gral.data.DataTable
-
- All Implemented Interfaces:
- DataSource, MutableDataSource, java.io.Serializable, java.lang.Iterable<java.lang.Comparable<?>>
public class DataTable extends AbstractDataSource implements MutableDataSource
An in-memory, random access implementation of a mutable data source using arrays to store its values.- See Also:
DataSource,MutableDataSource, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DataTable()DataTable(java.lang.Class<? extends java.lang.Comparable<?>>... types)Initializes a new instance with the specified number of columns and column types.DataTable(Column... columns)DataTable(DataSource source)Initializes a new instance with the column types, and data of another data source.DataTable(int cols, java.lang.Class<? extends java.lang.Comparable<?>> type)Initializes a new instance with the specified number of columns and a single column type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intadd(java.lang.Comparable<?>... values)Adds a row with the specified comparable values to the table.intadd(java.util.List<? extends java.lang.Comparable<?>> values)Adds a row with the specified container's elements to the table.voidadd(Record row)intadd(Row row)Adds the specified row to the table.voidclear()Deletes all rows this table contains.java.lang.Comparable<?>get(int col, int row)Returns the row with the specified index.intgetRowCount()Returns the number of rows of the data source.voidremove(int row)Removes a specified row from the table.voidremoveLast()Removes the last row from the table.<T> java.lang.Comparable<T>set(int col, int row, java.lang.Comparable<T> value)Sets the value of a cell specified by its column and row indexes.voidsetName(java.lang.String name)Sets the name of this series.voidsort(DataComparator... comparators)Sorts the table rows with the specified DataComparators.-
Methods inherited from class de.erichseifert.gral.data.AbstractDataSource
addDataListener, getColumn, getColumnCount, getColumnStatistics, getColumnTypes, getName, getRecord, getRow, getRowStatistics, getStatistics, isColumnNumeric, iterator, removeDataListener
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.erichseifert.gral.data.DataSource
addDataListener, getColumn, getColumnCount, getColumnStatistics, getColumnTypes, getName, getRecord, getRow, getRowStatistics, getStatistics, isColumnNumeric, removeDataListener
-
-
-
-
Constructor Detail
-
DataTable
public DataTable()
-
DataTable
public DataTable(java.lang.Class<? extends java.lang.Comparable<?>>... types)
Initializes a new instance with the specified number of columns and column types.- Parameters:
types- Type for each column
-
DataTable
public DataTable(int cols, java.lang.Class<? extends java.lang.Comparable<?>> type)Initializes a new instance with the specified number of columns and a single column type.- Parameters:
cols- Number of columnstype- Data type for all columns
-
DataTable
public DataTable(DataSource source)
Initializes a new instance with the column types, and data of another data source.- Parameters:
source- Data source to clone.
-
DataTable
public DataTable(Column... columns)
-
-
Method Detail
-
add
public int add(java.lang.Comparable<?>... values)
Adds a row with the specified comparable 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, anIllegalArgumentExceptionis thrown.- Specified by:
addin interfaceMutableDataSource- Parameters:
values- values to be added as a row- Returns:
- Index of the row that has been added.
-
add
public int add(java.util.List<? extends java.lang.Comparable<?>> 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, anIllegalArgumentExceptionis thrown.- Specified by:
addin interfaceMutableDataSource- Parameters:
values- values to be added as a row- Returns:
- Index of the row that has been added.
-
add
public int add(Row row)
Adds the specified row 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, anIllegalArgumentExceptionis thrown.- Specified by:
addin interfaceMutableDataSource- Parameters:
row- Row to be added- Returns:
- Index of the row that has been added.
-
add
public void add(Record row)
-
remove
public void remove(int row)
Removes a specified row from the table.- Specified by:
removein interfaceMutableDataSource- Parameters:
row- Index of the row to remove
-
removeLast
public void removeLast()
Removes the last row from the table.- Specified by:
removeLastin interfaceMutableDataSource
-
clear
public void clear()
Deletes all rows this table contains.- Specified by:
clearin interfaceMutableDataSource
-
get
public java.lang.Comparable<?> get(int col, int row)Returns the row with the specified index.- Specified by:
getin interfaceDataSource- Parameters:
col- index of the column to returnrow- index of the row to return- Returns:
- the specified value of the data cell
-
set
public <T> java.lang.Comparable<T> set(int col, int row, java.lang.Comparable<T> value)Sets the value of a cell specified by its column and row indexes.- Specified by:
setin interfaceMutableDataSource- Type Parameters:
T- Data type of the 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()
Returns the number of rows of the data source.- Specified by:
getRowCountin interfaceDataSource- Returns:
- number of rows in the data source.
-
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.- Specified by:
sortin interfaceMutableDataSource- Parameters:
comparators- comparators used for sorting
-
setName
public void setName(java.lang.String name)
Description copied from interface:MutableDataSourceSets the name of this series.- Specified by:
setNamein interfaceMutableDataSource- Parameters:
name- name to be set
-
-
DataMelt 3.0 © DataMelt by jWork.ORG