T
- The type of CellGame that uses the GameStates that can involve
this EventGroup's EventsU
- The type of GameState that can involve this EventGroup's Eventspublic class EventGroup<T extends CellGame,U extends GameState<T,U,?>>
extends java.lang.Object
An EventGroup is an ordered group of Events. Events in an EventGroup are ordered by integer priority values that are specified when they are added. Multiple instances of the same Event can be added to an EventGroup at the same or different priorities. Because an EventGroup's internal list of Events cannot be modified while it is being iterated over, the actual addition or removal of an Event to or from an EventGroup is delayed until any and all iterations over its Events have been completed. Multiple delayed instructions may be successfully given to EventGroups regarding the same Event without having to wait until all iterations have finished.
Constructor and Description |
---|
EventGroup()
Constructs an empty EventGroup.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Event<T,U> event,
int priority)
Adds to this EventGroup one instance of the specified Event at the
specified priority.
|
boolean |
iterating()
Returns whether any Iterators over this EventGroup's Events are in
progress.
|
SafeIterator<Event<T,U>> |
iterator()
Returns a new SafeIterator over this EventGroup's Events from highest to
lowest priority.
|
void |
perform(U state)
Iterates through this EventGroup's Events from highest to lowest priority
and performs each of them as part of the specified GameState.
|
boolean |
remove(Event<T,U> event,
int priority)
Removes from this EventGroup one instance of the specified Event at the
specified priority, if such an instance exists.
|
int |
size()
Returns the number of Event instances in this EventGroup.
|
public final int size()
public final boolean iterating()
public final SafeIterator<Event<T,U>> iterator()
public final void perform(U state)
state
- The GameState in which to involve this EventGroup's Events
when performing thempublic final void add(Event<T,U> event, int priority)
event
- The Event to addpriority
- The priority at which to add itpublic final boolean remove(Event<T,U> event, int priority)
event
- The Event to removepriority
- The priority at which to remove it