Class AbstractHistoricalCollection<E,C extends java.util.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:
java.lang.Iterable<E>,java.util.Collection<E>,HistoricalCollection<E>,HistoryManager.HistoricalElement
- Direct Known Subclasses:
AbstractHistoricalList,AbstractHistoricalQueue,AbstractHistoricalSortedSet,HistoricalHashSet,HistoricalLinkedHashSet
public abstract class AbstractHistoricalCollection<E,C extends java.util.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-2020 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 java.util.Collection<E>>Event for adding value to the collection.static classAbstractHistoricalCollection.EventCollection<E,C extends java.util.Collection<E>>Abstract super class for events that add or remove a value from the collection.static classAbstractHistoricalCollection.RemoveEvent<E,C extends java.util.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(java.util.Collection<? extends E> c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.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()java.util.Iterator<E>iterator()booleanremove(java.lang.Object value)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)intsize()java.lang.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
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAllin interfacejava.util.Collection<E>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<E>
-
remove
public boolean remove(java.lang.Object value)
- Specified by:
removein interfacejava.util.Collection<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<E>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<E>
-
iterator
public java.util.Iterator<E> iterator()
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<E>
-
-