T - value typeE - event typepublic abstract class AbstractHistorical<T,E extends AbstractHistorical.Event> extends Object implements HistoryManager.HistoricalElement
HistoryManager and in response to a request from the HistoryManager
will clear old events. Subclasses need to define their own events as extensions to AbstractHistorical.Event. This
class provides the following methods to subclasses to work with the events.
now(), returns the current time from the HistoryManager, 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 from before 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.E. 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-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
| Modifier and Type | Class and Description |
|---|---|
(package private) static interface |
AbstractHistorical.Event
Interface for event types.
|
static class |
AbstractHistorical.EventValue<T>
Standard event which stores a time and value.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHistorical(HistoryManager historyManager)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addEvent(E event)
Adds the event to the list of events.
|
void |
cleanUpHistory(org.djunits.value.vdouble.scalar.Duration history)
Removes events that are no longer needed to guarantee the history time.
|
protected E |
getEvent(org.djunits.value.vdouble.scalar.Time time)
Returns the most recent event from before or on
time, or the oldest if no such event. |
protected List<E> |
getEvents(org.djunits.value.vdouble.scalar.Time time)
Returns a list of events, ordered last to first, that includes all events after
time. |
protected E |
getLastEvent()
Returns the last event.
|
protected boolean |
isLastState(org.djunits.value.vdouble.scalar.Time time)
Returns whether the state at the given time is equal to the state at the current time.
|
protected org.djunits.value.vdouble.scalar.Time |
now()
Returns the current time.
|
protected void |
removeEvent(E event)
Removes the given event.
|
protected AbstractHistorical(HistoryManager historyManager)
historyManager - HistoryManager; history managerprotected final org.djunits.value.vdouble.scalar.Time now()
protected final List<E> getEvents(org.djunits.value.vdouble.scalar.Time time)
time.time - Time; past time up to which to include eventstimeprotected final E getEvent(org.djunits.value.vdouble.scalar.Time time)
time, or the oldest if no such event.time - Time; past time at which to obtain eventtimeprotected final E getLastEvent()
protected final boolean isLastState(org.djunits.value.vdouble.scalar.Time time)
time - Time; timeprotected final void removeEvent(E event)
event - E; event to removeprotected final void addEvent(E event)
event - E; event to addpublic final void cleanUpHistory(org.djunits.value.vdouble.scalar.Duration history)
cleanUpHistory in interface HistoryManager.HistoricalElementhistory - Duration; history time to keepCopyright © 2014–2018 Delft University of Technology. All rights reserved.