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

      • setConsoleHook

        @Deprecated(since="July 2020",
                    forRemoval=true)
        public void setConsoleHook​(@Nullable
                                   java.util.function.Consumer<java.lang.String> hook)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Deprecated Method
        Parameters:
        hook - hook
      • addState

        public void addState​(T key,
                             java.util.function.Consumer<StateMetadata<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.Consumer<StateMetadata<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