Package org.djutils.data
Class Table
- java.lang.Object
-
- org.djutils.data.Table
-
- All Implemented Interfaces:
Iterable<Row>
,Identifiable
- Direct Known Subclasses:
ListTable
public abstract class Table extends Object implements Iterable<Row>, Identifiable
Abstract table implementation taking care of the columns. Sub classes must provide anIterator
overRecord
s and may have methods to add data.Copyright (c) 2020-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
-
Constructor Summary
Constructors Constructor Description Table(String id, String description, Collection<Column<?>> columns)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Column<?>
getColumn(int columnNumber)
Return a specific column.Class<?>[]
getColumnDataTypes()
Return the column data types as a Class<?>[].String[]
getColumnDataTypeStrings()
Return the column data types as a String[].String[]
getColumnDescriptions()
Return the column descriptions as a String[].String[]
getColumnIds()
Return the column ids as a String[].int
getColumnNumber(String columnId)
Returns the number of the column with given id.int
getColumnNumber(Column<?> column)
Returns the number of the column in this table.ImmutableList<Column<?>>
getColumns()
Returns the list of columns.String
getDescription()
Returns the description.String
getId()
int
getNumberOfColumns()
Returns the number of columns.abstract boolean
isEmpty()
Returns whether the table is empty.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Constructor Detail
-
Table
public Table(String id, String description, Collection<Column<?>> columns)
Constructor.- Parameters:
id
- String; iddescription
- String; descriptioncolumns
- Collection<Column<?>>; columns- Throws:
NullPointerException
- when id, description or columns is nullIllegalArgumentException
- when id is empty, duplicate column ids, or there are zero columns
-
-
Method Detail
-
getId
public String getId()
- Specified by:
getId
in interfaceIdentifiable
-
getDescription
public String getDescription()
Returns the description.- Returns:
- description
-
getColumns
public ImmutableList<Column<?>> getColumns()
Returns the list of columns.- Returns:
- list of columns
-
getColumn
public Column<?> getColumn(int columnNumber)
Return a specific column.- Parameters:
columnNumber
- int; number of the column.- Returns:
- Column<?>; column.
- Throws:
IllegalArgumentException
- if the column number is < 0 or >getNumberOfColumns() - 1
.
-
getNumberOfColumns
public int getNumberOfColumns()
Returns the number of columns.- Returns:
- number of columns
-
getColumnNumber
public int getColumnNumber(Column<?> column)
Returns the number of the column in this table.- Parameters:
column
- Column<?>; column.- Returns:
- int; column number.
- Throws:
IllegalArgumentException
- if the column is not in the table.
-
getColumnNumber
public int getColumnNumber(String columnId)
Returns the number of the column with given id.- Parameters:
columnId
- String; column id.- Returns:
- int; column number.
- Throws:
IllegalArgumentException
- if the column is not in the table.
-
getColumnIds
public String[] getColumnIds()
Return the column ids as a String[].- Returns:
- String[]; the column ids
-
getColumnDescriptions
public String[] getColumnDescriptions()
Return the column descriptions as a String[].- Returns:
- String[] the column headers
-
getColumnDataTypes
public Class<?>[] getColumnDataTypes()
Return the column data types as a Class<?>[].- Returns:
- Class<?>[] the column data types
-
getColumnDataTypeStrings
public String[] getColumnDataTypeStrings()
Return the column data types as a String[]. Each data type is presented as the full class name or the primitive name. In case of an array, the result is preceded by an "[" for each dimension. After one or more "[" symbols, the class name is preceded by an "L" for a non-primitive class or interface, and by "I" for integer, "Z" for boolean, "B" for byte, "C" for char, "D" for double, "F" for float, "J" for long and "S" for short. So for a column with a double, "double" is returned. For a column with a "Double", "java.lang.Double" is returned, for an int[][], "[[I" is returned, and for a Long[], "[Ljava.lang.Long" is returned.- Returns:
- String[] the column data types as an array of Strings
-
isEmpty
public abstract boolean isEmpty()
Returns whether the table is empty.- Returns:
- whether the table is empty
-
-