A simple state machine. More...
Public Member Functions | |
void | addTransition (T fromState, T toState) |
Adds an allowed transition. More... | |
boolean | canTransition (T toState) |
Determines whether a transition to the specified state is allowed. More... | |
long | getLastStateMillis () |
Gets the length of time spent in the last state, in milliseconds. More... | |
long | getLastStateTicks () |
Gets the length of time spent in the last state, in ticks. More... | |
T | getState () |
Gets the state. More... | |
long | getSystemTimestamp () |
Gets the system timestamp of the last state transition. More... | |
boolean | isReachable (T state) |
Determines whether a transition to a specified state is possible (even via intermediate hops). More... | |
StateMachine (T initialState) | |
Initializes a new instance of the fm.liveswitch.StateMachine class. More... | |
boolean | transition (T toState) |
Transitions to the specified state. More... | |
Protected Member Functions | |
int | getStateValue () |
Gets the state value. More... | |
abstract int | stateToValue (T state) |
Converts a state to an integer value. More... | |
abstract T | valueToState (int value) |
Converts an integer value to a state. More... | |
A simple state machine.
fm.liveswitch.StateMachine< T >.StateMachine | ( | T | initialState | ) |
Initializes a new instance of the fm.liveswitch.StateMachine class.
initialState | The initial state. |
void fm.liveswitch.StateMachine< T >.addTransition | ( | T | fromState, |
T | toState | ||
) |
Adds an allowed transition.
fromState | The "from" state. |
toState | The "to" state. |
boolean fm.liveswitch.StateMachine< T >.canTransition | ( | T | toState | ) |
Determines whether a transition to the specified state is allowed.
toState | The "to" state. |
long fm.liveswitch.StateMachine< T >.getLastStateMillis | ( | ) |
Gets the length of time spent in the last state, in milliseconds.
long fm.liveswitch.StateMachine< T >.getLastStateTicks | ( | ) |
Gets the length of time spent in the last state, in ticks.
T fm.liveswitch.StateMachine< T >.getState | ( | ) |
Gets the state.
|
protected |
Gets the state value.
long fm.liveswitch.StateMachine< T >.getSystemTimestamp | ( | ) |
Gets the system timestamp of the last state transition.
boolean fm.liveswitch.StateMachine< T >.isReachable | ( | T | state | ) |
Determines whether a transition to a specified state is possible (even via intermediate hops).
state | The "to" state. |
|
abstractprotected |
Converts a state to an integer value.
state | The state. |
boolean fm.liveswitch.StateMachine< T >.transition | ( | T | toState | ) |
Transitions to the specified state.
toState | The "to" state. |
|
abstractprotected |
Converts an integer value to a state.
value | The integer value. |