Package jsl.simulation
Class State
- java.lang.Object
-
- jsl.simulation.State
-
- All Implemented Interfaces:
StateAccessorIfc
,GetNameIfc
,IdentityIfc
- Direct Known Subclasses:
Request.RequestState
,ResourceUnit.ResourceState
,Transporter.TransporterState
public class State extends java.lang.Object implements IdentityIfc, StateAccessorIfc
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
myCollectSojournStatisticsFlag
Indicates whether or not statistics should be collected on time spent in the state.protected double
myEnteredTime
time the state was last enteredprotected double
myExitedTime
time the state was last exitedprotected boolean
myInStateIndicator
indicates whether or not currently in the stateprotected java.lang.String
myName
The name of the stateprotected double
myNumTimesEntered
number of times the state was enteredprotected double
myNumTimesExited
number of times the state was exitedprotected Statistic
myStatistic
statistical collectorprotected double
myTimeFirstEntered
time that the state was entered for the first timeprotected double
myTotalStateTime
Total time spent in state
-
Constructor Summary
Constructors Constructor Description State()
State(int number)
Create a state with no name and do not use a Statistic object to collect additional statisticsState(int number, boolean useStatistic)
Create a state with no nameState(java.lang.String name)
State(java.lang.String name, boolean useStatistic)
State(java.lang.String name, int number)
Create a state with given name and do not use a Statistic object to collect additional statisticsState(java.lang.String name, int number, boolean useStatistic)
Create a state with given name and indicate usage of a Statistic object to collect additional statistics
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
enter(double time)
Causes the state to be entered If the state has already been entered then nothing happens.double
exit(double time)
Causes the state to be exitedint
getId()
Gets a uniquely assigned integer identifier for this state.java.lang.String
getName()
Gets this model element's name.int
getNumber()
double
getNumberOfTimesEntered()
Gets the number of times the state was entereddouble
getNumberOfTimesExited()
Gets the number of times the state was exitedboolean
getSojournTimeCollectionFlag()
Indicates whether or not statistics should be collected on the sojourn times within the statejava.util.Optional<Statistic>
getSojournTimeStatistic()
Gets a statistic that collected sojourn timesdouble
getTimeFirstEntered()
double
getTimeStateEntered()
Gets the time that the state was last entereddouble
getTimeStateExited()
Gets the time that the state was last exiteddouble
getTotalTimeInState()
Gets the total time spent in the statevoid
initialize()
Initializes the state back to new - not in state - enter/exited time/time first entered = Double.NaN - total time in state = 0.0 - enter/exited count = 0.0 - sojourn statistics reset if turned onboolean
isEntered()
Gets whether or not the state has been enteredprotected void
onEnter()
can be overwritten by subclasses to perform work when the state is enteredprotected void
onExit()
can be overwritten by subclasses to perform work when the state is exitedvoid
resetSojournTimeStatistics()
Resets the statistics collected on the sojourn time in the statevoid
resetStateCollection()
Resets the counters for the number of times a state was entered, exited, and the total time spent in the state This does not effect whether or the state has been entered, the time it was last entered, or the time it was last exited.void
setName(java.lang.String str)
Sets the name of this statejava.lang.String
toString()
void
turnOffSojournTimeCollection()
Turns off statistical collection of the sojourn times in the statevoid
turnOnSojournTimeCollection()
Turns on statistical collection for the sojourn time in the state-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.simulation.StateAccessorIfc
getTimeInState
-
-
-
-
Field Detail
-
myName
protected java.lang.String myName
The name of the state
-
myInStateIndicator
protected boolean myInStateIndicator
indicates whether or not currently in the state
-
myNumTimesEntered
protected double myNumTimesEntered
number of times the state was entered
-
myNumTimesExited
protected double myNumTimesExited
number of times the state was exited
-
myEnteredTime
protected double myEnteredTime
time the state was last entered
-
myTimeFirstEntered
protected double myTimeFirstEntered
time that the state was entered for the first time
-
myExitedTime
protected double myExitedTime
time the state was last exited
-
myTotalStateTime
protected double myTotalStateTime
Total time spent in state
-
myStatistic
protected Statistic myStatistic
statistical collector
-
myCollectSojournStatisticsFlag
protected boolean myCollectSojournStatisticsFlag
Indicates whether or not statistics should be collected on time spent in the state. The default is false
-
-
Constructor Detail
-
State
public State()
-
State
public State(int number)
Create a state with no name and do not use a Statistic object to collect additional statistics
-
State
public State(java.lang.String name, int number)
Create a state with given name and do not use a Statistic object to collect additional statistics- Parameters:
name
- The name of the state
-
State
public State(java.lang.String name)
-
State
public State(java.lang.String name, boolean useStatistic)
-
State
public State(int number, boolean useStatistic)
Create a state with no name- Parameters:
useStatistic
- True means collect additional statistics
-
State
public State(java.lang.String name, int number, boolean useStatistic)
Create a state with given name and indicate usage of a Statistic object to collect additional statistics- Parameters:
name
- The name of the statenumber
- a number assigned to the state for labeling purposesuseStatistic
- True means collect sojourn time statistics
-
-
Method Detail
-
getNumber
public final int getNumber()
- Returns:
- the number assigned to the state, by default getId() if never assigned
-
setName
public final void setName(java.lang.String str)
Sets the name of this state- Parameters:
str
- The name as a string.
-
getName
public final java.lang.String getName()
Gets this model element's name.- Specified by:
getName
in interfaceGetNameIfc
- Returns:
- The name of the model element.
-
getId
public final int getId()
Gets a uniquely assigned integer identifier for this state. This identifier is assigned when the state is created. It may vary if the order of creation changes.- Specified by:
getId
in interfaceIdentityIfc
- Returns:
- The identifier for the state.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isEntered
public final boolean isEntered()
Gets whether or not the state has been entered- Specified by:
isEntered
in interfaceStateAccessorIfc
- Returns:
- True means that the state has been entered
-
enter
public final void enter(double time)
Causes the state to be entered If the state has already been entered then nothing happens. Preconditions: time must be >= 0, must not be Double.NaN and must not be Double.Infinity- Parameters:
time
- The time that the state is being entered
-
onEnter
protected void onEnter()
can be overwritten by subclasses to perform work when the state is entered
-
exit
public final double exit(double time)
Causes the state to be exited- Parameters:
time
- the time that the state was exited, must be >= time entered, >= 0, not Double.NaN not Double.Infinity- Returns:
- the time spent in the state as a double
-
onExit
protected void onExit()
can be overwritten by subclasses to perform work when the state is exited
-
initialize
public final void initialize()
Initializes the state back to new - not in state - enter/exited time/time first entered = Double.NaN - total time in state = 0.0 - enter/exited count = 0.0 - sojourn statistics reset if turned on
-
getSojournTimeCollectionFlag
public final boolean getSojournTimeCollectionFlag()
Indicates whether or not statistics should be collected on the sojourn times within the state- Returns:
- Returns the collect sojourn time flag.
-
turnOnSojournTimeCollection
public final void turnOnSojournTimeCollection()
Turns on statistical collection for the sojourn time in the state
-
turnOffSojournTimeCollection
public final void turnOffSojournTimeCollection()
Turns off statistical collection of the sojourn times in the state
-
resetSojournTimeStatistics
public final void resetSojournTimeStatistics()
Resets the statistics collected on the sojourn time in the state
-
resetStateCollection
public final void resetStateCollection()
Resets the counters for the number of times a state was entered, exited, and the total time spent in the state This does not effect whether or the state has been entered, the time it was last entered, or the time it was last exited. To reset those quantities and the state counters use initialize()
-
getTimeFirstEntered
public final double getTimeFirstEntered()
- Returns:
- The time that the state was first entered
-
getTimeStateEntered
public final double getTimeStateEntered()
Gets the time that the state was last entered- Specified by:
getTimeStateEntered
in interfaceStateAccessorIfc
- Returns:
- A double representing the time that the state was last entered
-
getTimeStateExited
public final double getTimeStateExited()
Gets the time that the state was last exited- Specified by:
getTimeStateExited
in interfaceStateAccessorIfc
- Returns:
- A double representing the time that the state was last exited
-
getNumberOfTimesEntered
public final double getNumberOfTimesEntered()
Gets the number of times the state was entered- Specified by:
getNumberOfTimesEntered
in interfaceStateAccessorIfc
- Returns:
- A double representing the number of times entered
-
getNumberOfTimesExited
public final double getNumberOfTimesExited()
Gets the number of times the state was exited- Specified by:
getNumberOfTimesExited
in interfaceStateAccessorIfc
- Returns:
- A double representing the number of times exited
-
getSojournTimeStatistic
public final java.util.Optional<Statistic> getSojournTimeStatistic()
Gets a statistic that collected sojourn times- Specified by:
getSojournTimeStatistic
in interfaceStateAccessorIfc
- Returns:
- A statistic for sojourn times or null if the statistics were never turned on
-
getTotalTimeInState
public final double getTotalTimeInState()
Gets the total time spent in the state- Specified by:
getTotalTimeInState
in interfaceStateAccessorIfc
- Returns:
- a double representing the total sojourn time
-
-