Class AbstractHistorical<T,E extends org.opentrafficsim.core.perception.AbstractHistorical.Event>
- java.lang.Object
-
- org.opentrafficsim.core.perception.AbstractHistorical<T,E>
-
- Type Parameters:
T- value typeE- event type
- All Implemented Interfaces:
HistoryManager.HistoricalElement
- Direct Known Subclasses:
AbstractHistoricalCollection,AbstractHistoricalMap,HistoricalParameters,HistoricalValue
public abstract class AbstractHistorical<T,E extends org.opentrafficsim.core.perception.AbstractHistorical.Event> extends Object implements HistoryManager.HistoricalElement
Base class for objects or properties that can be perceived from their actual state in the past. The principle by which a past state is determined is by storing an internal event for each change to the object. Each event can be reversed, and by working from a current state backwards, any previous state within the available history can be restored.
This class couples the historical to aHistoryManagerand in response to a request from theHistoryManagerwill clear old events. Subclasses need to define their own events as extensions toAbstractHistorical.Event. This class provides the following methods to subclasses to work with the events.now(), returns the current time from theHistoryManager, which needs to be stored with each event.getEvents(Time), returns all events between now and the given time, ordered from recent to old.getEvent(Time), returns the most recent event no later than the given time.getLastEvent(), returns the most recent event.removeEvent(Event), removes (oldest occurrence off) the event.addEvent(Event), add the event.
addEvent(Event), where the event stores information such that the event can be restored. When an old state is requested, one or more events can be obtained with either of the get methods, after which they are applied to restore a previous state in a manner depending on the nature of the subclass.
This class is defined with a single event type parameterE. Subclasses can use different event classes, so long as all of them derive from a common ancestor. For instance an 'add' and a 'remove' event that inherit from an abstract super.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 classAbstractHistorical.EventValue<T>Standard event which stores a time and value.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractHistorical(HistoryManager historyManager)Construct a new AbstractHistorical.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddEvent(E event)Adds an Event to the list of events.voidcleanUpHistory(Duration history)Removes events that are no longer needed to guarantee the history time.protected EgetEvent(Time time)Returns the most recent event no later thantime, or the oldest if no such event.protected List<E>getEvents(Time time)Returns a list of events, ordered last to first, that includes all events aftertime.protected EgetLastEvent()Retrieve the last Event.protected booleanisLastState(Time time)Report whether the state at the given time is equal to the state at the current time.protected Timenow()Returns the current time.protected voidremoveEvent(E event)Removes the given Event.
-
-
-
Constructor Detail
-
AbstractHistorical
protected AbstractHistorical(HistoryManager historyManager)
Construct a new AbstractHistorical.- Parameters:
historyManager- HistoryManager; history manager
-
-
Method Detail
-
now
protected final Time now()
Returns the current time.- Returns:
- Time; current time
-
getEvents
protected final List<E> getEvents(Time time)
Returns a list of events, ordered last to first, that includes all events aftertime.- Parameters:
time- Time; past time up to which to include events- Returns:
- List; list of events, ordered last to first, that includes all events after
time
-
getEvent
protected final E getEvent(Time time)
Returns the most recent event no later thantime, or the oldest if no such event.- Parameters:
time- Time; past time at which to obtain event- Returns:
- E; most recent Event from before, or at
time
-
getLastEvent
protected final E getLastEvent()
Retrieve the last Event.- Returns:
- E; last Event
-
isLastState
protected final boolean isLastState(Time time)
Report whether the state at the given time is equal to the state at the current time.- Parameters:
time- Time; time- Returns:
- boolean; true if the state at the given time is equal to the state at the current time; false if the state at the given time is not equal to the state at the current time
-
removeEvent
protected final void removeEvent(E event)
Removes the given Event.- Parameters:
event- E; event to remove
-
addEvent
protected final void addEvent(E event)
Adds an Event to the list of events.- Parameters:
event- E; event to add
-
cleanUpHistory
public final void cleanUpHistory(Duration history)
Removes events that are no longer needed to guarantee the history time. This method is invoked by the history manager.- Specified by:
cleanUpHistoryin interfaceHistoryManager.HistoricalElement- Parameters:
history- Duration; history time to keep
-
-