Class QuantityTable<Q extends Quantity<Q>>

Type Parameters:
Q - the quantity type
All Implemented Interfaces:
Serializable, Additive<QuantityTable<Q>>, Scalable<QuantityTable<Q>>, Value<QuantityTable<Q>,Q>, Hadamard<QuantityTable<?>,QuantityTable<SIQuantity>>

public class QuantityTable<Q extends Quantity<Q>> extends Table<Q,QuantityTable<Q>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q>>
QuantityTable is a two-dimensonal table with quantities. The QuantityTable allows for Hadamard (element-wise) operations, but not for vector/matrix operations. A QuantityTable can be transformed to a MatrixNxM or vice versa.

Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.

Author:
Alexander Verbraeck
See Also:
  • Constructor Details

    • QuantityTable

      public QuantityTable(DataGridSi<?> dataGridSi, Unit<?,Q> displayUnit)
      Create a new NxM QuantityTable with a unit, based on a DataGrid storage object. This constructor assumes dataSi stores SI values. Note: NO safe copy is made.
      Parameters:
      dataGridSi - the data of the matrix, in SI unit.
      displayUnit - the display unit to use
  • Method Details

    • instantiateSi

      public QuantityTable<Q> instantiateSi(double[] siNew)
      Description copied from class: VectorMatrix
      Return a new vector or matrix with the given SI or BASE values.
      Specified by:
      instantiateSi in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      siNew - the values for the new vector or matrix in row-major format
      Returns:
      a new matrix with the provided SI or BASE values
    • instantiateSi

      public QuantityTable<SIQuantity> instantiateSi(double[] siNew, SIUnit siUnit)
      Description copied from class: VectorMatrix
      Return a new vector or matrix in SI-units with the given SI or BASE values.
      Specified by:
      instantiateSi in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      siNew - the values for the new vector or matrix in row-major format
      siUnit - the new unit for the new vector or matrix
      Returns:
      a new matrix with the provided SI or BASE values
    • getDataGrid

      public DataGridSi<?> getDataGrid()
      Return the internal datagrid object, so we can retrieve data from it.
      Returns:
      the internal datagrid object
    • getSiArray

      public double[] getSiArray()
      Description copied from class: VectorMatrix
      Return a row-major array of SI-values for this matrix or vector. This is guaranteed to be a safe copy.
      Specified by:
      getSiArray in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Returns:
      the row-major array of SI-values (safe copy)
    • unsafeSiArray

      public double[] unsafeSiArray()
      Description copied from class: VectorMatrix
      Return a row-major possibly UNSAFE array of SI-values for this matrix or vector. The method might give access to the underlying data structure, so treat the data carefully.
      Specified by:
      unsafeSiArray in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Returns:
      the row-major array of SI-values (safe copy)
    • si

      public double si(int row, int col) throws IndexOutOfBoundsException
      Description copied from class: Table
      Return the si-value at position (row, col), where both row and col are 0-based values.
      Specified by:
      si in class Table<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      row - the row (0-based)
      col - the column (0-based)
      Returns:
      the si-value at position (row, col)
      Throws:
      IndexOutOfBoundsException - when row or col < 0 or larger than number of rows/columns - 1.
    • getRowVector

      public VectorN.Row<Q> getRowVector(int row)
      Description copied from class: Table
      Return a quantity row (0-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.
      Specified by:
      getRowVector in class Table<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      row - the row number to retrieve (0-based)
      Returns:
      a row vector with the data at the given row
    • mgetRowVector

      public VectorN.Row<Q> mgetRowVector(int mRow)
      Description copied from class: Table
      Return a quantity row (1-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.
      Specified by:
      mgetRowVector in class Table<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      mRow - the row number to retrieve (1-based)
      Returns:
      a row vector with the data at the given row
    • getColumnVector

      public VectorN.Col<Q> getColumnVector(int col)
      Description copied from class: Table
      Return a quantity column (0-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.
      Specified by:
      getColumnVector in class Table<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      col - the column number to retrieve (0-based)
      Returns:
      a column vector with the data at the given column
    • mgetColumnVector

      public VectorN.Col<Q> mgetColumnVector(int mCol)
      Description copied from class: Table
      Return a quantity column (1-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.
      Specified by:
      mgetColumnVector in class Table<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      mCol - the column number to retrieve (1-based)
      Returns:
      a column vector with the data at the given column
    • getRowSi

      public double[] getRowSi(int row)
      Description copied from class: Table
      Return an array with SI-values for the given row (0-based) from the table or matrix.
      Specified by:
      getRowSi in class Table<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      row - the row number to retrieve (0-based)
      Returns:
      an array with SI-values with the data at the given row
    • getColumnSi

      public double[] getColumnSi(int col)
      Description copied from class: Table
      Return an array with SI-values for the given column (0-based) from the table or matrix.
      Specified by:
      getColumnSi in class Table<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Parameters:
      col - the column number to retrieve (0-based)
      Returns:
      an array with SI-values with the data at the given column
    • rows

      public int rows()
      Description copied from class: VectorMatrix
      Return the number of rows.
      Specified by:
      rows in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Returns:
      the number of rows
    • cols

      public int cols()
      Description copied from class: VectorMatrix
      Return the number of columns.
      Specified by:
      cols in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Returns:
      the number of columns
    • nonZeroCount

      public int nonZeroCount()
      Description copied from class: VectorMatrix
      Return the number of non-zero entries in the vector, matrix or table. Note that NaN and Infinity count as a non-zero element. The value -0.0 counts as 0.0.
      Specified by:
      nonZeroCount in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Returns:
      the number of non-zero entries in the vector, matrix or table
    • transpose

      public QuantityTable<Q> transpose()
      Return the transposed quantity table. A transposed quantity table has the same unit as the original one.
      Specified by:
      transpose in class VectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q extends Quantity<Q>>>
      Returns:
      the transposed quantity table
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • of

      public static <Q extends Quantity<Q>> QuantityTable<Q> of(double[] dataInUnit, int rows, int cols, Unit<?,Q> unit)
      Create a new QuantityTable with a unit, based on a row-major array with values in the given unit.
      Type Parameters:
      Q - the quantity type
      Parameters:
      dataInUnit - the table values {a11, a12, ..., A1M, ..., aN1, aN2, ..., aNM} expressed in the unit
      rows - the number of rows
      cols - the number of columns
      unit - the unit of the data, also used as the display unit
      Returns:
      a new QuantityTable with a unit
      Throws:
      IllegalArgumentException - when dataInUnit does not contain a square number of values
    • ofSi

      public static <Q extends Quantity<Q>> QuantityTable<Q> ofSi(double[] dataSi, int rows, int cols, Unit<?,Q> displayUnit)
      Create a QuantityTable without needing generics, based on a row-major array with SI-values.
      Type Parameters:
      Q - the quantity type
      Parameters:
      dataSi - the table values {a11, a12, ..., A1M, ..., aN1, aN2, ..., aNM} as an array using SI units
      rows - the number of rows
      cols - the number of columns
      displayUnit - the display unit to use
      Returns:
      a new QuantityTable with a unit
      Throws:
      IllegalArgumentException - when dataSi does not contain a square number of values
    • of

      public static <Q extends Quantity<Q>> QuantityTable<Q> of(Q[] data, int rows, int cols)
      Create a QuantityTable without needing generics, based on a row-major array of quantities. The unit is taken from the first quantity in the array.
      Type Parameters:
      Q - the quantity type
      Parameters:
      data - the table values {a11, a12, ..., A1M, ..., aN1, aN2, ..., aNM} expressed as an array of quantities
      rows - the number of rows
      cols - the number of columns
      Returns:
      a new QuantityTable with a unit
      Throws:
      IllegalArgumentException - when data does not contain a square number of quantities
    • ofSi

      public static <Q extends Quantity<Q>> QuantityTable<Q> ofSi(double[][] gridSi, Unit<?,Q> displayUnit)
      Create a new QuantityTable with a unit, based on a 2-dimensional grid with SI-values.
      Type Parameters:
      Q - the quantity type
      Parameters:
      gridSi - the table values {{a11, a12, ..., A1M}, ..., {aN1, aN2, ..., aNM}} expressed in the SI or base unit
      displayUnit - the unit of the data, which will also be used as the display unit
      Returns:
      a new QuantityTable with a unit
      Throws:
      IllegalArgumentException - when dataInUnit does not contain a square number of values
    • of

      public static <Q extends Quantity<Q>> QuantityTable<Q> of(double[][] gridInUnit, Unit<?,Q> unit)
      Create a new QuantityTable with a unit, based on a 2-dimensional grid with values in the given unit.
      Type Parameters:
      Q - the quantity type
      Parameters:
      gridInUnit - the table values {{a11, a12, ..., A1M}, ..., {aN1, aN2, ..., aNM}} expressed in the unit
      unit - the unit of the values, also used as the display unit
      Returns:
      a new QuantityTable with a unit
      Throws:
      IllegalArgumentException - when dataInUnit does not contain a square number of values
    • of

      public static <Q extends Quantity<Q>> QuantityTable<Q> of(Q[][] grid)
      Create a QuantityTable without needing generics, based on a 2-dimensional grid of quantities. The unit is taken from the first quantity in the grid.
      Type Parameters:
      Q - the quantity type
      Parameters:
      grid - the table values {{a11, a12, ..., A1M}, ..., {aN1, aN2, ..., aNM}} expressed as a 2-dimensional array of quantities
      Returns:
      a new QuantityTable with a unit
      Throws:
      IllegalArgumentException - when dataInUnit does not contain a square number of quantities
    • as

      public <TQ extends Quantity<TQ>> QuantityTable<TQ> as(Unit<?,TQ> targetUnit) throws IllegalArgumentException
      Return the QuantityTable 'as' a QuantityTable with a known quantity, using a unit to express the result in. Throw a Runtime exception when the SI units of this vector and the target vector do not match.
      Type Parameters:
      TQ - target quantity type
      Parameters:
      targetUnit - the unit to convert the quantity table to
      Returns:
      a quantity table typed in the target quantity table class
      Throws:
      IllegalArgumentException - when the units do not match
    • format

      public String format()
      Concise description of this quantity table.
      Returns:
      a String with the quantity table, with the unit attached.
    • format

      public String format(TableFormat format)
      String representation of this quantity table after applying the format.
      Parameters:
      format - the format to apply for the quantity table
      Returns:
      a String representation of this quantity table, formatted according to the given format
    • format

      public String format(Unit<?,Q> targetUnit)
      String representation of this quantity table, expressed in the specified unit.
      Parameters:
      targetUnit - the unit into which the values of the quantity table are converted for display
      Returns:
      printable string with the quantity table's values expressed in the specified unit