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.
        Parameters:
        expectedCurrentState - the expected current state
        Throws:
        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.
        Parameters:
        expectedCurrentState - an expected state
        state - a state
        Returns:
        true if successful. false indicates that the actual value was not equal to the expected value.
        Throws:
        IllegalStateTransitionException - if the state is unknown state, or the transition from the current state to the specified state is illegal
      • getCurrentState

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