E - The type of SimEvents supported.public abstract class AbstractSimEventList<E extends SimEvent> extends TreeSet<E> implements SimEventList<E>
TreeSet-based implementation of SimEventList.
Note that in the default implementation, events that have the same time, are processed in random order!
The implementation is not thread-safe. An event list is really meant to be processed and operated upon by a single thread only.
Last javadoc Review: Jan de Jongh, TNO, 20180402, r5.1.0.
| Modifier and Type | Field and Description |
|---|---|
protected static boolean |
USE_ARRAY_OPTIMIZATION
When
true, this class and possibly some sub-classes maintain various array copies of collections
often iterated over, like listeners, and uses array iteration instead of Collection iteration. |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSimEventList(Comparator comparator,
double defaultResetTime,
Class<E> eventClass)
Creates a new (abstract) event list (main constructor).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addAll(Collection<? extends E> collection)
Overridden in order (ensure) the setting the de-conflict value on the event added.
|
void |
addListener(SimEventListResetListener l)
Adds a listener to this event list.
|
protected void |
checkUpdate(double newTime)
Checks the progress of time and notifies listeners when an update has taken place.
|
protected void |
checkUpdate(E e)
Checks the progress of time when processing a given event
and notifies listeners when an update has taken place.
|
protected void |
fireEmpty()
Fires an empty-event-list notification to registered listeners.
|
protected void |
fireNextEvent()
Fires a next-event notification to registered listeners.
|
protected void |
fireReset()
Fires a reset notification to registered listeners.
|
protected void |
fireUpdate()
Fires an update notification to registered listeners.
|
double |
getDefaultResetTime()
Gets the default reset time, the time on the event list after it is reset (without explicit time argument).
|
Class<E> |
getSimEventClass()
|
SimEventFactory<? extends E> |
getSimEventFactory()
Gets the factory for
SimEvents created by this SimEventList. |
double |
getTime()
Returns the current time during processing of the event list.
|
Function<SimEventList,String> |
getToStringFunction()
Gets the function that generates the string for
toString(). |
void |
removeListener(SimEventListResetListener l)
Removes a listener from this event list.
|
void |
reset(double time)
Resets the event list to a specific time.
|
void |
run()
Overridden to make the default method final.
|
void |
runSingleStep()
Runs a single (the first) event from the event list ("single-stepping").
|
void |
runUntil(double endTime,
boolean inclusive,
boolean setTimeToEndTime)
Runs the event list until it is empty, interrupted, or until a specific point in time has been reached.
|
void |
setDefaultResetTime(double defaultResetTime)
Sets the default reset time, the time on the event list after it is reset (without explicit time argument).
|
void |
setSimEventFactory(SimEventFactory<? extends E> eventFactory)
Sets the factory for
SimEvents created by this SimEventList. |
void |
setToStringFunction(Function<SimEventList,String> toStringFunction)
Sets the function that generates the string for
toString(). |
String |
toString()
Returns a string representation of this event list (final, but customizable).
|
add, ceiling, clear, clone, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, remove, size, spliterator, subSet, subSet, tailSet, tailSetequals, hashCode, removeAllcontainsAll, retainAll, toArray, toArrayfinalize, getClass, notify, notifyAll, wait, wait, waitprint, print, reschedule, reset, schedule, schedule, schedule, schedule, scheduleNow, scheduleNow, scheduleNowcomparator, first, headSet, last, spliterator, subSet, tailSetadd, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArrayparallelStream, removeIf, streamprotected static final boolean USE_ARRAY_OPTIMIZATION
true, this class and possibly some sub-classes maintain various array copies of collections
often iterated over, like listeners, and uses array iteration instead of Collection iteration.protected AbstractSimEventList(Comparator comparator, double defaultResetTime, Class<E> eventClass)
Unless an event-factory is registered after construction,
the base class for SimEvents supported (E)
must feature a constructor with no arguments,
see setSimEventFactory(org.javades.jsimulation.r5.SimEventFactory<? extends E>).
comparator - The comparator for SimEvents.defaultResetTime - The default reset time.eventClass - The base class SimEvents supported.IllegalArgumentException - If eventClass is null.TreeSet.TreeSet(java.util.Comparator)public final Function<SimEventList,String> getToStringFunction()
toString().
Note that this class turns toString() final.
If this method returns null, which is the default after construction,
the toString() method returns a compile-time default string.
toString().toString(),
setToStringFunction(java.util.function.Function<org.javades.jsimulation.r5.SimEventList, java.lang.String>)public final void setToStringFunction(Function<SimEventList,String> toStringFunction)
toString().
Note that this class turns toString() final.
If the function is set to null, the toString() method returns a compile-time default string.
toStringFunction - The function returning the appropriate print string when this is supplied as argument.toString(),
getToStringFunction()public final String toString()
Since we intend to create one of more final sub-classes,
but still want end-users to be able to customize the printed output,
this method applies the getToStringFunction() if present.
Otherwise, it returns a compile-time default string.
toString in class AbstractCollection<E extends SimEvent>getToStringFunction(),
setToStringFunction(java.util.function.Function<org.javades.jsimulation.r5.SimEventList, java.lang.String>)public final double getDefaultResetTime()
SimEventList
The default value (i.e., the default reset time if not set explicitly through SimEventList.setDefaultResetTime(double))
is negative infinity.
getDefaultResetTime in interface SimEventList<E extends SimEvent>SimEventList.reset(),
SimEventList.reset(double)public final void setDefaultResetTime(double defaultResetTime)
SimEventList
The value supplied (obviously) survives resets;
the last value set through this method is only
used by SimEventList.reset().
This method can be called at any time; the default reset time is only used while actually performing a reset.
setDefaultResetTime in interface SimEventList<E extends SimEvent>defaultResetTime - The new default reset time (minus and positive infinity are allowed).SimEventList.reset(),
SimEventList.reset(double)public final double getTime()
SimEventListgetTime in interface SimEventList<E extends SimEvent>public final Class<E> getSimEventClass()
SimEventListgetSimEventClass in interface SimEventList<E extends SimEvent>Class of allowable SimEvents in this event list.public final SimEventFactory<? extends E> getSimEventFactory()
SimEventListSimEvents created by this SimEventList.getSimEventFactory in interface SimEventList<E extends SimEvent>null.public final void setSimEventFactory(SimEventFactory<? extends E> eventFactory)
SimEventListSimEvents created by this SimEventList.setSimEventFactory in interface SimEventList<E extends SimEvent>eventFactory - The event factory; may be null to stop using it.public final boolean addAll(Collection<? extends E> collection)
Overridden and made final to ensure this method uses the abstract TreeSet.add(E) method.
You do not have to override this method in case you want to change
setting the de-conflict value; override TreeSet.add(E) instead.
addAll in interface Collection<E extends SimEvent>addAll in interface Set<E extends SimEvent>addAll in class TreeSet<E extends SimEvent>collection - See TreeSet.addAll(java.util.Collection<? extends E>).TreeSet.addAll(java.util.Collection<? extends E>).SimEvent.setSimEventListDeconflictValue(long)public void reset(double time)
SimEventListRemoves all events, and sets time to the given value. An exception is thrown if the event list is currently running.
This method ignores the default reset time, as given by SimEventList.getDefaultResetTime(),
but does not change that value.
reset in interface SimEventList<E extends SimEvent>time - The new time of the event list.SimEventList.run()protected final void checkUpdate(double newTime)
newTime - The new time.IllegalArgumentException - If this is not the first update (after construction or after a reset)
and the new time is strictly smaller than the current time.getTime(),
fireUpdate()protected final void checkUpdate(E e)
e - The event being processed.IllegalArgumentException - If the event is null or if this is not the first update
(after construction or after a reset)
and the new time on the event is strictly smaller than the current time.getTime(),
fireUpdate()public final void run()
run in interface Runnablerun in interface SimEventList<E extends SimEvent>SimEventList.run()public final void runUntil(double endTime,
boolean inclusive,
boolean setTimeToEndTime)
SimEventList
After returning from this method, it can be invoked later, but the end time passed must not decrease in this sequence.
See also SimEventList.reset(double).
Optionally, but only if inclusive == true, the time on the event list is increased to the endTime
argument.
Otherwise, not that the current time on the event list may be smaller than the end time provided!
runUntil in interface SimEventList<E extends SimEvent>endTime - The time until which to run the event list.inclusive - Whether to include events at the end time parameter.setTimeToEndTime - Whether to increase the current time to the end time given after processing the applicable events
(ignored if inclusive == false).SimEventList.getTime(),
SimEvent.getTime(),
SimEventList.run()public final void runSingleStep()
runSingleStep in interface SimEventList<E extends SimEvent>public final void addListener(SimEventListResetListener l)
SimEventListaddListener in interface SimEventList<E extends SimEvent>l - The listener to be added, ignored if null.public final void removeListener(SimEventListResetListener l)
SimEventListremoveListener in interface SimEventList<E extends SimEvent>l - The listener to be removed, ignored if null or not present.protected final void fireReset()
protected final void fireUpdate()
protected final void fireEmpty()
protected final void fireNextEvent()
Copyright © 2018. All rights reserved.