T
- The subclass of CellGame that uses this ThinkerGroup's Thinkers'
CellGameStatesU
- The subclass of CellGameState uses this ThinkerGroup's ThinkersV
- The subclass of Thinker that this ThinkerGroup's Thinkers arepublic abstract class ThinkerGroup<T extends CellGame,U extends CellGameState<T,U,V>,V extends Thinker<T,U,V>>
extends java.lang.Object
A ThinkerGroup is a group of Thinkers that can be iterated over. Thinkers may be assigned to one ThinkerGroup each. Because a ThinkerGroup's internal list of Thinkers cannot be modified while it is being iterated over, the actual addition or removal of a Thinker to or from a ThinkerGroup is delayed until any and all current iterations over its Thinkers, such as the periods during which Thinkers perform their timeUnitActions() or frameActions(), have been completed. Multiple delayed instructions may be successfully given to ThinkerGroups regarding the same Thinker without having to wait until all iterations have finished.
Constructor and Description |
---|
ThinkerGroup() |
Modifier and Type | Method and Description |
---|---|
boolean |
addThinker(V thinker)
Adds the specified Thinker to this ThinkerGroup if it is not already
assigned to a ThinkerGroup, and if doing so would not create a loop of
assignments in which Thinkers are directly or indirectly assigned to
themselves.
|
void |
addThinkerActions(V thinker)
Actions for this ThinkerGroup to take immediately after adding a Thinker
to itself, before the Thinker takes its addedActions().
|
int |
getNumThinkers()
Returns the number of Thinkers that are assigned to this ThinkerGroup.
|
boolean |
iteratingThroughThinkers()
Returns whether any Iterators over this ThinkerGroup's list of Thinkers
are in progress.
|
void |
removeAllSubThinkers()
Removes from their ThinkerGroups all of the Thinkers that are directly or
indirectly assigned to this ThinkerGroup.
|
void |
removeAllThinkers()
Removes from this ThinkerGroup all of the Thinkers that are currently
assigned to it.
|
boolean |
removeLineage(V thinker)
Removes from their ThinkerGroups all of the Thinkers that are directly or
indirectly assigned to this ThinkerGroup, and are either assigned to or
assignees of the specified Thinker.
|
boolean |
removeThinker(V thinker)
Removes the specified Thinker from this ThinkerGroup if it is currently
assigned to it.
|
void |
removeThinkerActions(V thinker)
Actions for this ThinkerGroup to take immediately before removing a
Thinker from itself, after the Thinker takes its removedActions().
|
SafeIterator<V> |
thinkerIterator()
Returns a new Iterator over this ThinkerGroup's list of Thinkers.
|
void |
updateThinkerListActions()
Actions for this ThinkerGroup to take immediately after updating its list
of Thinkers.
|
public final int getNumThinkers()
public final boolean iteratingThroughThinkers()
public final SafeIterator<V> thinkerIterator()
public final boolean addThinker(V thinker)
thinker
- The Thinker to be addedpublic final boolean removeThinker(V thinker)
thinker
- The Thinker to be removedpublic final void removeAllThinkers()
public final void removeAllSubThinkers()
public final boolean removeLineage(V thinker)
thinker
- The Thinker with which the removed Thinkers must share a
lineage of assignmentspublic void addThinkerActions(V thinker)
thinker
- The Thinker that was addedpublic void removeThinkerActions(V thinker)
thinker
- The Thinker that is about to be removedpublic void updateThinkerListActions()