StateMachineFactory

class StateMachineFactory<State : Enum<State>, Event : Enum<Event>, GuardKey : Enum<GuardKey>, ActionKey : Enum<ActionKey>, Memento>(stateType: Class<State>, eventType: Class<Event>, guardKeyType: Class<GuardKey>, actionKeyType: Class<ActionKey>)

A StateMachineFactory enables a client to dynamically specify and assemble a finite state machine. In particular, the factory allows a client to flexibly define a particular FSM while ignoring specification and evaluation order dependency. Validation is postponed until final assembly time, at which time a ValidationException will be thrown in the event of incorrect or incomplete specification; otherwise, the constructed FSM provably reflects the client specification.

Author

Mark van Gulik

Todd L Smith

Parameters

State

The type of states (an Enum).

Event

The type of events (an Enum).

GuardKey

The type of guard keys (an Enum).

ActionKey

The type of action keys (an Enum).

Memento

The type of memento.

stateType

The kind of states.

eventType

The kind of events.

guardKeyType

The kind of guard keys.

actionKeyType

The kind of action keys.

Constructors

Link copied to clipboard
constructor(stateType: Class<State>, eventType: Class<Event>, guardKeyType: Class<GuardKey>, actionKeyType: Class<ActionKey>)

Construct a new StateMachineFactory primed to create a new instance of the specified kind of state machine.

Functions

Link copied to clipboard
fun addAutomaticTransition(startState: State, guardKey: GuardKey?, actionKey: ActionKey?, endState: State)

Add an automatically taken transition.

Link copied to clipboard
fun addTransition(startState: State, event: Event?, guardKey: GuardKey?, actionKey: ActionKey?, endState: State)

Add a transition arc.

Link copied to clipboard

Create an instance of the finite state machine described by the StateMachineFactory.

Link copied to clipboard
fun defineAction(actionKey: ActionKey, action: (Memento) -> Unit)

Bind an action key to an action.

Link copied to clipboard
fun defineGuard(guardKey: GuardKey, guard: (Memento) -> Boolean)

Bind a guard key to a guard.

Link copied to clipboard
fun setEntryAction(state: State, actionKey: ActionKey)

Set the entry action key that indicates which action to invoke when entering the specified state.

Link copied to clipboard
fun setExitAction(state: State, actionKey: ActionKey)

Set the exit action key that indicates which action to invoke when exiting the specified state.

Link copied to clipboard
fun setInitialState(initialState: State)

Record the canonical initial state of the target state machine.