Class AbstractHistoricalCollection<E,C extends Collection<E>>
- java.lang.Object
-
- org.opentrafficsim.core.perception.AbstractHistorical<E,AbstractHistoricalCollection.EventCollection<E,C>>
-
- org.opentrafficsim.core.perception.collections.AbstractHistoricalCollection<E,C>
-
- Type Parameters:
E
- element typeC
- collection type
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,HistoricalCollection<E>
,HistoryManager.HistoricalElement
- Direct Known Subclasses:
AbstractHistoricalList
,AbstractHistoricalQueue
,AbstractHistoricalSortedSet
,HistoricalHashSet
,HistoricalLinkedHashSet
public abstract class AbstractHistoricalCollection<E,C extends Collection<E>> extends AbstractHistorical<E,AbstractHistoricalCollection.EventCollection<E,C>> implements HistoricalCollection<E>
Collection-valued historical state. The current collection is always maintained, and past states of the collection are obtained by applying the events between now and the requested time in reverse.
This implementation is suitable for sets, as add and remove events to retrieve historical states are only created if indeed the underlying collection is changed.Set
introduces no new methods relative toCollection
.
TheIterator
returned by this class does not support theremove()
method.Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version 1 jan. 2018
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractHistoricalCollection.AddEvent<E,C extends Collection<E>>
Event for adding value to the collection.static class
AbstractHistoricalCollection.EventCollection<E,C extends Collection<E>>
Abstract super class for events that add or remove a value from the collection.static class
AbstractHistoricalCollection.RemoveEvent<E,C extends Collection<E>>
Event for removing value from the collection.-
Nested classes/interfaces inherited from class org.opentrafficsim.core.perception.AbstractHistorical
AbstractHistorical.EventValue<T>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractHistoricalCollection(HistoryManager historyManager, C collection)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E value)
boolean
addAll(Collection<? extends E> c)
void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
protected C
fill(C collection)
Fill collection with the current collection.protected C
fill(Time time, C collection)
Fill collection with the collection at the given simulation time.protected C
getCollection()
Returns the internal collection.boolean
isEmpty()
Iterator<E>
iterator()
boolean
remove(Object value)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
-
Methods inherited from class org.opentrafficsim.core.perception.AbstractHistorical
addEvent, cleanUpHistory, getEvent, getEvents, getLastEvent, isLastState, now, removeEvent
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, spliterator, stream, toArray
-
Methods inherited from interface org.opentrafficsim.core.perception.collections.HistoricalCollection
get, get, removeIf
-
-
-
-
Constructor Detail
-
AbstractHistoricalCollection
protected AbstractHistoricalCollection(HistoryManager historyManager, C collection)
Constructor.- Parameters:
historyManager
- HistoryManager; history managercollection
- C; initial collection
-
-
Method Detail
-
getCollection
protected final C getCollection()
Returns the internal collection.- Returns:
- C; internal collection
-
fill
protected final C fill(C collection)
Fill collection with the current collection.- Parameters:
collection
- C; collection to fill- Returns:
- C; input collection filled
-
fill
protected final C fill(Time time, C collection)
Fill collection with the collection at the given simulation time.- Parameters:
time
- Time; timecollection
- C; collection to fill- Returns:
- C; input collection filled
-
add
public boolean add(E value)
- Specified by:
add
in interfaceCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAll
in interfaceCollection<E>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
-
remove
public boolean remove(Object value)
- Specified by:
remove
in interfaceCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<E>
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<E>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
-
-