public class EventCounter extends BasicSimEntity
A generic counter for SimEvents that occur during a simulation run.
As events are heard, a Map is built up that keeps a count for each
type of event by name. Only the name matters - events with the same
name but different signatures are treated as the same event. Events of
the same name from different objects are also treaded identically.
Internally, the Map stores the key as the name of the event and the value
as an int[]
array of length 1. This avoids the immutability
problem with Java's primitive wrapper classes, in which the value must be
extracted and a new object created.
The counts are built up on the fly. When a new event is heard, a new
entry is created in the Map. If an old event is heard, the int[]
array is retrieved from the Map and the the first (and only) value incremented.
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,int[]> |
eventCounts |
eventList, property
DEFAULT_ENTITY_NAME, DEFAULT_EVENT_NAME, DEFAULT_PRIORITY, EVENT_METHOD_PREFIX, NL
Constructor and Description |
---|
EventCounter()
Instantiate the Map of event names and counts
|
Modifier and Type | Method and Description |
---|---|
int |
getEventCount(java.lang.String eventName)
If this event has not been heard, returns -1.
|
java.util.Map<java.lang.String,int[]> |
getEventCounts() |
java.lang.String[] |
getHeardEvents() |
void |
handleSimEvent(SimEvent simEvent)
Does nothing, since this will never schedule any events
|
void |
processSimEvent(SimEvent simEvent)
If a non-Run event is heard that has been heard before,
increment its count.
|
void |
reset()
Clear the entire map of all names and counts
|
addPropertyChangeListener, addPropertyChangeListener, attemptSchedule, clearAddedProperty, compareTo, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAddedProperties, getEventList, getEventListID, getName, getPriority, getPropertiesString, getProperty, getProperty, getPropertyChangeListeners, getSerial, interrupt, interrupt, interruptAll, interruptAll, interruptAll, interruptAllWithArgs, interruptAllWithArgs, isClearAddedPropertiesOnReset, isJustDefinedProperties, isPersistant, isReRunnable, isVerbose, parametersMatch, removePropertyChangeListener, removePropertyChangeListener, resetNextSerial, setClearAddedPropertiesOnReset, setEventList, setEventListID, setJustDefinedProperties, setName, setPersistant, setPriority, setProperty, setVerbose, toString, waitDelay, waitDelay, waitDelay, waitDelay
addSimEventListener, getSimEventListeners, notifyListeners, removeSimEventListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addSimEventListener, getSimEventListeners, notifyListeners, removeSimEventListener
public void reset()
reset
in interface ReRunnable
reset
in class BasicSimEntity
public void handleSimEvent(SimEvent simEvent)
handleSimEvent
in interface SimEventScheduler
handleSimEvent
in class BasicSimEntity
simEvent
- Given SimEventpublic void processSimEvent(SimEvent simEvent)
processSimEvent
in interface SimEventListener
processSimEvent
in class BasicSimEntity
simEvent
- Given SimEventpublic java.util.Map<java.lang.String,int[]> getEventCounts()
public java.lang.String[] getHeardEvents()
public int getEventCount(java.lang.String eventName)
eventName
- Name of event count is desired for