StateMachine

class StateMachine<ID, V : Value<ID, V, S>, S : State<ID, V, S>> @Inject constructor(transitions: Set<Transition<ID, V, S>>, transitioner: Transitioner<ID, Transition<ID, V, S>, V, S>)

A Guice-managed wrapper around KFSM's Transitioner that provides convenient access to discovered transitions.

This class is responsible for:

  1. Managing the set of available transitions

  2. Providing type-safe access to specific transitions

  3. Executing transitions using the underlying Transitioner

Parameters

V

The type of value being managed by the state machine

S

The type of state, must extend State

Constructors

Link copied to clipboard
@Inject
constructor(transitions: Set<Transition<ID, V, S>>, transitioner: Transitioner<ID, Transition<ID, V, S>, V, S>)

Functions

Link copied to clipboard
fun execute(value: V, transition: Transition<ID, V, S>): Result<V>

Executes the given transition on the provided value.

Link copied to clipboard

Returns all transitions that are valid for the given state.

Link copied to clipboard
inline fun <T : Transition<ID, V, S>> getTransition(): T

Gets a specific transition by its type.

fun <T : Transition<ID, V, S>> getTransition(klass: KClass<T>): T

Gets a specific transition by its KClass.

Link copied to clipboard
fun transitionToState(value: V, targetState: S): Result<V>

Attempts to transition the given value to the specified state.