Package org.djutils.data
Class Table
java.lang.Object
org.djutils.data.Table
- Direct Known Subclasses:
ListTable
Abstract table implementation taking care of the columns. Sub classes must provide an
Iterator
over Record
s
and may have methods to add data.
Copyright (c) 2020-2024 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
ConstructorDescriptionTable
(String id, String description, Collection<Column<?>> columns) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionColumn<?>
getColumn
(int columnNumber) Return a specific column.Class<?>[]
Return the column data types as a Class<?String[]
Return the column data types as a String[].String[]
Return the column descriptions as a String[].String[]
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.org.djutils.immutablecollections.ImmutableList<Column<?>>
Returns the list of columns.Returns the description.getId()
int
Returns the number of columns.abstract boolean
isEmpty()
Returns whether the table is empty.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 Details
-
Table
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 Details
-
getId
- Specified by:
getId
in interfaceorg.djutils.base.Identifiable
-
getDescription
Returns the description.- Returns:
- description
-
getColumns
Returns the list of columns.- Returns:
- list of columns
-
getColumn
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
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
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
Return the column ids as a String[].- Returns:
- String[]; the column ids
-
getColumnDescriptions
Return the column descriptions as a String[].- Returns:
- String[] the column headers
-
getColumnDataTypes
Return the column data types as a Class<?>[].- Returns:
- Class<?>[] the column data types
-
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
-
toString
-