fm.liveswitch.StateMachine< T > Class Template Referenceabstract

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...
 
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...
 

Detailed Description

A simple state machine.

Constructor & Destructor Documentation

◆ StateMachine()

fm.liveswitch.StateMachine< T >.StateMachine ( initialState)

Initializes a new instance of the fm.liveswitch.StateMachine class.

Parameters
initialStateThe initial state.

Member Function Documentation

◆ addTransition()

void fm.liveswitch.StateMachine< T >.addTransition ( fromState,
toState 
)

Adds an allowed transition.

Parameters
fromStateThe "from" state.
toStateThe "to" state.

◆ canTransition()

boolean fm.liveswitch.StateMachine< T >.canTransition ( toState)

Determines whether a transition to the specified state is allowed.

Parameters
toStateThe "to" state.
Returns
true
if a transition to the specified state is allowed; otherwise,
false
.

◆ getLastStateMillis()

long fm.liveswitch.StateMachine< T >.getLastStateMillis ( )

Gets the length of time spent in the last state, in milliseconds.

◆ getLastStateTicks()

long fm.liveswitch.StateMachine< T >.getLastStateTicks ( )

Gets the length of time spent in the last state, in ticks.

◆ getState()

T fm.liveswitch.StateMachine< T >.getState ( )

Gets the state.

◆ getStateValue()

int fm.liveswitch.StateMachine< T >.getStateValue ( )
protected

Gets the state value.

◆ getSystemTimestamp()

long fm.liveswitch.StateMachine< T >.getSystemTimestamp ( )

Gets the system timestamp of the last state transition.

◆ isReachable()

boolean fm.liveswitch.StateMachine< T >.isReachable ( state)

Determines whether a transition to a specified state is possible (even via intermediate hops).

Parameters
stateThe "to" state.
Returns
true
if a transition to the specified state is possible; otherwise,
false
.

◆ stateToValue()

abstract int fm.liveswitch.StateMachine< T >.stateToValue ( state)
abstractprotected

Converts a state to an integer value.

Parameters
stateThe state.

◆ transition()

boolean fm.liveswitch.StateMachine< T >.transition ( toState)

Transitions to the specified state.

Parameters
toStateThe "to" state.
Returns
true
if a transition to the specified state is allowed; otherwise,
false
.

◆ valueToState()

abstract T fm.liveswitch.StateMachine< T >.valueToState ( int  value)
abstractprotected

Converts an integer value to a state.

Parameters
valueThe integer value.