Class Table

java.lang.Object
org.djutils.data.Table
All Implemented Interfaces:
Iterable<Row>, org.djutils.base.Identifiable
Direct Known Subclasses:
ListTable

public abstract class Table extends Object implements Iterable<Row>, org.djutils.base.Identifiable
Abstract table implementation taking care of the columns. Sub classes must provide an Iterator over Records 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 Details

    • Table

      public Table(String id, String description, Collection<Column<?>> columns)
      Constructor.
      Parameters:
      id - String; id
      description - String; description
      columns - Collection<Column<?>>; columns
      Throws:
      NullPointerException - when id, description or columns is null
      IllegalArgumentException - when id is empty, duplicate column ids, or there are zero columns
  • Method Details

    • getId

      public String getId()
      Specified by:
      getId in interface org.djutils.base.Identifiable
    • getDescription

      public String getDescription()
      Returns the description.
      Returns:
      description
    • getColumns

      public org.djutils.immutablecollections.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
    • toString

      public String toString()
      Overrides:
      toString in class Object