Package 

Class FiniteStateMachine

  • All Implemented Interfaces:

    
    public final class FiniteStateMachine<S extends Object, E extends Object>
    
                        

    This class represents a Finite State Machine. It can be only in one possible state at a time out of the set of possible states S. It can handle events from the set E.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final StateFlow<S> stateFlow
      private final S state
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final StateFlow<S> getStateFlow() The current state as StateFlow.
      final S getState()
      final Unit sendEvent(E event) Sends an event to the state machine.
      final S stay() Keeps the FSM in its current state.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FiniteStateMachine

        FiniteStateMachine(S initialState, Map<KClass<out S>, Map<KClass<out E>, Function2<S, E, S>>> stateFunctions, Function2<S, E, S> defaultEventHandler)
        Parameters:
        initialState - The initial state.
    • Method Detail

      • getStateFlow

         final StateFlow<S> getStateFlow()

        The current state as StateFlow.

      • sendEvent

         final Unit sendEvent(E event)

        Sends an event to the state machine. The entry point to change state.

      • stay

         final S stay()

        Keeps the FSM in its current state. Usually used when handling events that don't need to make a transition.

        onEvent<SomeEvent> { state, event -> stay() }