Class StateMachine<T>


  • public class StateMachine<T>
    extends java.lang.Object
    • Field Detail

      • defaultStateKey

        public T defaultStateKey
      • lastStateKey

        public T lastStateKey
      • desiredStateKey

        public T desiredStateKey
    • Constructor Detail

      • StateMachine

        public StateMachine​(java.lang.String name)
        Create a StateMachine
        Parameters:
        name - Name of the machine (for logging)
    • Method Detail

      • addState

        public void addState​(T key,
                             java.util.function.Function<StateMetadata<T>,​T> action)
        Add a state to the StateMachine
        Parameters:
        key - State key
        action - Action to be run
      • setDefaultState

        public void setDefaultState​(T key,
                                    java.util.function.Function<StateMetadata<T>,​T> action)
        Add a state to the StateMachine, and set it as the default. This state will be called upon any error in state handling, or when no state is set.
        Parameters:
        key - State key
        action - Action to be run
      • removeState

        public void removeState​(T key)
        Remove a state from the StateMachine
        Parameters:
        key - State key
      • update

        public void update()
        Update the machine. This MUST be called periodically
      • setState

        public void setState​(T key)
        Set the StateMachine's state
        Parameters:
        key - State key
      • getCurrentState

        @Nullable
        public T getCurrentState()
        Get the system's current state
        Returns:
        current state