Class StateMachine

  • public final class StateMachine
    extends Object
    A finite state machine that can be created with user defined states and transitions.
    • Method Detail

      • checkState

        public void checkState​(Enum expectedCurrentState)
        Checks whether the current state is same as the expectedCurrentState.
        expectedCurrentState - the expected current state
        RuntimeException - if the expectedCurrentState is not same as the actual current state
      • compareAndSetState

        public boolean compareAndSetState​(Enum expectedCurrentState,
                                          Enum state)
                                   throws IllegalStateTransitionException
        Atomically sets the state to the given updated state if the current state equals to the expected state.
        expectedCurrentState - an expected state
        state - a state
        true if successful. false indicates that the actual value was not equal to the expected value.
        IllegalStateTransitionException - if the state is unknown state, or the transition from the current state to the specified state is illegal
      • getCurrentState

        public Enum getCurrentState()
        the name of the current state.