Interface Stateful<S extends State>

Type Parameters:
S - the state type
All Known Implementing Classes:
CommandManager

@API(status=STABLE) public interface Stateful<S extends State>
A simple state machine.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Requires that the current state() is equal to the expected state, and fails exceptionally if the states are different.
    Returns the current state.
    boolean
    Transitions from the in state to the out state, unless the current state() is identical to the out state.
    default void
    Transitions from the in state to the out state, unless the current state() is identical to the out state.
  • Method Details

    • state

      @NonNull S state()
      Returns the current state.
      Returns:
      the current state
    • transitionIfPossible

      boolean transitionIfPossible(@NonNull S in, @NonNull S out)
      Transitions from the in state to the out state, unless the current state() is identical to the out state.
      Parameters:
      in - the starting state
      out - the ending state
      Returns:
      true if the state transition was successful, or the current state is identical to the out state
    • requireState

      default void requireState(@NonNull S expected)
      Requires that the current state() is equal to the expected state, and fails exceptionally if the states are different.
      Parameters:
      expected - the expected state
      Throws:
      IllegalStateException - if the current state() is different from the expected state
    • transitionOrThrow

      default void transitionOrThrow(@NonNull S in, @NonNull S out)
      Transitions from the in state to the out state, unless the current state() is identical to the out state.
      Parameters:
      in - the starting state
      out - the ending state
      Throws:
      IllegalStateException - if state transition is not possible