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.Setintroduces no new methods relative toCollection.
TheIteratorreturned 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 classAbstractHistoricalCollection.AddEvent<E,C extends Collection<E>>Event for adding value to the collection.static classAbstractHistoricalCollection.EventCollection<E,C extends Collection<E>>Abstract super class for events that add or remove a value from the collection.static classAbstractHistoricalCollection.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 protectedAbstractHistoricalCollection(HistoryManager historyManager, C collection)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E value)booleanaddAll(Collection<? extends E> c)voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)protected Cfill(C collection)Fill collection with the current collection.protected Cfill(Time time, C collection)Fill collection with the collection at the given simulation time.protected CgetCollection()Returns the internal collection.booleanisEmpty()Iterator<E>iterator()booleanremove(Object value)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()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:
addin interfaceCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>
-
remove
public boolean remove(Object value)
- Specified by:
removein interfaceCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<E>
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>
-
-