Class StateMachine<T extends Enum<T>>

  • Type Parameters:
    T - states.

    public final class StateMachine<T extends Enum<T>>
    extends Object
    A simple state machine.

    This class is not thread safe!

    • Method Detail

      • assertState

        @SafeVarargs
        public final boolean assertState​(@NonNull
                                         T... expected)
        Verify expected state.
        Parameters:
        expected - expected states.
        Returns:
        true if the current state at the time of the call, is one of the expected states.
      • setState

        public boolean setState​(@NonNull
                                T nextState)
        Set the new state. If it is legal to transition to the new state, from the current state, do so, returning the now-previous state. If the transition is illegal do nothing and return null.
        Parameters:
        nextState - the requested new state
        Returns:
        the previous state, if the transition succeeds; null otherwise.