Class StateMachine<Context,State extends State<Context>>

java.lang.Object
dev.prozilla.pine.core.state.StateMachine<Context,State>
All Implemented Interfaces:
StateProvider<Context,State>

public class StateMachine<Context,State extends State<Context>> extends Object implements StateProvider<Context,State>
Utility class for managing a finite-state machine (FSM).
  • Field Details

  • Constructor Details

    • StateMachine

      public StateMachine(State initialState, Context context)
      Creates a state machine for a given context and enters its initial state.
      Parameters:
      initialState - The initial state of the state machine
      context - The context of the state
  • Method Details

    • changeState

      public void changeState(State from, State to)
      Changes the state of this state machine, only if the current state matches a given state.
      Parameters:
      from - Determines what the current state must be in order for this change to be performed.
      to - The new state
    • changeState

      public void changeState(State newState)
      Exits the current state and enters a new state, unless both are equal.
      Parameters:
      newState - The new state to enter
    • getState

      public State getState()
      Specified by:
      getState in interface StateProvider<Context,State extends State<Context>>
      Returns:
      The current state of the state machine.
    • isState

      public boolean isState(State state)
      Description copied from interface: StateProvider
      Checks whether the state machine is in a given state.
      Specified by:
      isState in interface StateProvider<Context,State extends State<Context>>
    • getLogger

      protected Logger getLogger()