Package org.opentrafficsim.kpi.sampling
Class ListTable
- java.lang.Object
-
- org.opentrafficsim.kpi.sampling.AbstractTable
-
- org.opentrafficsim.kpi.sampling.ListTable
-
- All Implemented Interfaces:
java.lang.Iterable<Record>
,Identifiable
,Table
public class ListTable extends AbstractTable
List implementation ofTable
.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
ListTable.ListRecord
Record in aListTable
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRecord(java.lang.Object[] data)
Adds a record to the table.void
addRecord(java.util.Map<Column<?>,java.lang.Object> data)
Adds a record to the table.void
addRecordByColumnIds(java.util.Map<java.lang.String,java.lang.Object> data)
Adds a record to the table.boolean
isEmpty()
Returns whether the table is empty.java.util.Iterator<Record>
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:-
Methods inherited from class org.opentrafficsim.kpi.sampling.AbstractTable
getColumns, getDescription, getId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opentrafficsim.kpi.sampling.Table
getNumberOfColumns
-
-
-
-
Constructor Detail
-
ListTable
public ListTable(java.lang.String id, java.lang.String description, java.util.Collection<Column<?>> columns)
Constructor.- Parameters:
id
- String; iddescription
- String; descriptioncolumns
- Collection<Column<?>>; columns
-
-
Method Detail
-
iterator
public java.util.Iterator<Record> 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
-
addRecord
public void addRecord(java.util.Map<Column<?>,java.lang.Object> data)
Adds a record to the table.- Parameters:
data
- Map<String, Object>; data with values given per column- Throws:
java.lang.IllegalArgumentException
- when the size or data types in the data map do not comply to the columns
-
addRecordByColumnIds
public void addRecordByColumnIds(java.util.Map<java.lang.String,java.lang.Object> data)
Adds a record to the table.- Parameters:
data
- Map<String, Object>; data with values given per column id- Throws:
java.lang.IllegalArgumentException
- when the size or data types in the data map do not comply to the columns
-
addRecord
public void addRecord(java.lang.Object[] data)
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:
java.lang.IllegalArgumentException
- when the size, order or data types in theObject[]
do not comply to the columns
-
-