Package org.djutils.data
Class ListDataTable
java.lang.Object
org.djutils.data.AbstractDataTable
org.djutils.data.ListDataTable
- All Implemented Interfaces:
Iterable<DataRecord>
,org.djutils.base.Identifiable
,DataTable
public class ListDataTable extends AbstractDataTable
List implementation of
Table
.
Copyright (c) 2020-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ListDataTable.ListRecord
Record in aListTable
. -
Constructor Summary
Constructors Constructor Description ListDataTable(String id, String description, Collection<DataColumn<?>> columns)
Constructor with a regular collection.ListDataTable(String id, String description, org.djutils.immutablecollections.ImmutableList<DataColumn<?>> columns)
Constructor with an immutable list. -
Method Summary
Modifier and Type Method Description void
addRecord(Object[] data)
Adds a record to the table.void
addRecordByColumnIds(Map<String,Object> data)
Adds a record to the table, based on a map with column ids and values.void
addRecordByColumnIds(org.djutils.immutablecollections.ImmutableMap<String,Object> data)
Adds a record to the table, based on an immutable map with column ids and values.void
addRecordByColumns(Map<DataColumn<?>,Object> data)
Adds a record to the table, based on a map with columns and values.void
addRecordByColumns(org.djutils.immutablecollections.ImmutableMap<DataColumn<?>,Object> data)
Adds a record to the table, based on an immutable map with columns and values.boolean
isEmpty()
Returns whether the table is empty.Iterator<DataRecord>
iterator()
It is imperative that the user manually synchronize on the returned list when traversing it viaIterator
,Spliterator
orStream
when there is a risk of adding records while traversing the iterator:String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.djutils.data.DataTable
getColumnDataTypes, getColumnDataTypeStrings, getColumnDescriptions, getColumnIds, getNumberOfColumns
-
Constructor Details
-
ListDataTable
Constructor with a regular collection.- Parameters:
id
- String; iddescription
- String; descriptioncolumns
- Collection<Column<?>>; columns
-
ListDataTable
public ListDataTable(String id, String description, org.djutils.immutablecollections.ImmutableList<DataColumn<?>> columns)Constructor with an immutable list.- Parameters:
id
- String; iddescription
- String; descriptioncolumns
- ImmutableList<Column<?>>; columns
-
-
Method Details
-
iterator
It is imperative that the user manually synchronize on the returned list when traversing it viaIterator
,Spliterator
orStream
when there is a risk of adding records while traversing the iterator:List list = Collections.synchronizedList(new ArrayList()); ... synchronized (list) { Iterator i = list.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); }
Failure to follow this advice may result in non-deterministic behavior.
-
isEmpty
public boolean isEmpty()Returns whether the table is empty.- Returns:
- whether the table is empty
-
addRecordByColumns
Adds a record to the table, based on a map with columns and values.- Parameters:
data
- Map<String, Object>; data with values given per column- Throws:
IllegalArgumentException
- when the size or data types in the data map do not comply to the columnsNullPointerException
- when data is null
-
addRecordByColumns
public void addRecordByColumns(org.djutils.immutablecollections.ImmutableMap<DataColumn<?>,Object> data)Adds a record to the table, based on an immutable map with columns and values.- Parameters:
data
- Map<String, Object>; data with values given per column- Throws:
IllegalArgumentException
- when the size or data types in the data map do not comply to the columnsNullPointerException
- when data is null
-
addRecordByColumnIds
Adds a record to the table, based on a map with column ids and values.- Parameters:
data
- Map<String, Object>; immutable data with values given per column id- Throws:
IllegalArgumentException
- when the size or data types in the data map do not comply to the columnsNullPointerException
- when data is null
-
addRecordByColumnIds
public void addRecordByColumnIds(org.djutils.immutablecollections.ImmutableMap<String,Object> data)Adds a record to the table, based on an immutable map with column ids and values.- Parameters:
data
- Map<String, Object>; data with values given per column id- Throws:
IllegalArgumentException
- when the size or data types in the data map do not comply to the columnsNullPointerException
- when data is null
-
addRecord
Adds a record to the table. The order in which the elements in the array are offered should be the same as the order of the columns.- Parameters:
data
- Object[]; record data- Throws:
IllegalArgumentException
- when the size, order or data types in theObject[]
do not comply to the columnsNullPointerException
- when data is null
-
toString
-