Enum State
- All Implemented Interfaces:
Serializable,Comparable<State>
The State captures the main functionality of the state machine. It represents a specific state in
the state machine, and holds all transitions possible from a specific state.
The state transition diagram is as follows:
+--[a]--> W --[b]--> Y --[e]---+
| ^ |
Initial-+ | |
| | +--> (Z)-----[g]---> Terminal
+--[c]--> X --[b]----+ |
| |
+--------[d]---------+
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe initial state from which all state sequences start.Special state returned by the State.transition(...) function when attempting an illegal state transition.The terminal state in the state machine.State 'W'.State 'X'.State 'Y'.State 'Z'. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this state is a terminal state.Returns an event type that, if applied as a transition on this state, will result in an illegal state transition.randomTransition(Random rnd) Picks a random transition, based on the probabilities of the outgoing transitions of this state.transition(EventType evt) Gets the state after transitioning from this state based on the given event.static StateReturns the enum constant of this type with the specified name.static State[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
Terminal
The terminal state in the state machine. -
InvalidTransition
Special state returned by the State.transition(...) function when attempting an illegal state transition. -
Z
State 'Z'. -
Y
State 'Y'. -
X
State 'X'. -
W
State 'W'. -
Initial
The initial state from which all state sequences start.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
isTerminal
public boolean isTerminal()Checks if this state is a terminal state. A terminal state has no outgoing transitions. -
transition
Gets the state after transitioning from this state based on the given event. If the transition is valid, this returns the new state, and if this transition is illegal, it returns [[InvalidTransition]].- Parameters:
evt- The event that defined the transition.- Returns:
- The new state, or [[InvalidTransition]].
-
randomTransition
Picks a random transition, based on the probabilities of the outgoing transitions of this state.- Parameters:
rnd- The random number generator to use.- Returns:
- A pair of (transition event , new state).
-
randomInvalidTransition
Returns an event type that, if applied as a transition on this state, will result in an illegal state transition.- Parameters:
rnd- The random number generator to use.- Returns:
- And event type for an illegal state transition.
-