org.firstinspires.ftc.robotcore.external

## Class StateMachine

- java.lang.Object
- - org.firstinspires.ftc.robotcore.external.StateMachine

-     public class StateMachine
      extends java.lang.Object

  Infrastructure for a very simple generic state machine. Part of a collection of classes including State, Event, and StateTransition. All this class does is manage a directed graph and execute transitions on events. Create instances of a state machine by deriving from this class and defining states, events, and transitions. See usages of StateMachine for reference implementations.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected State` | `currentState`
    `protected java.util.ArrayList<Event>` | `maskList`
    `protected java.util.HashMap<State,java.util.ArrayList<StateTransition>>` | `stateGraph`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StateMachine()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addTransition(StateTransition transition)` addTransition Adds a transition to the state machine.
    `State` | `consumeEvent(Event event)` consumeEvent Executes a state transition and returns the new state.
    `void` | `maskEvent(Event event)`
    `protected void` | `start(State state)` start Define the start state of the state machine.
    `java.lang.String` | `toString()`
    `protected State` | `transition(Event event)`
    `void` | `unMaskEvent(Event event)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### currentState

          protected State currentState

    - #### stateGraph

          protected java.util.HashMap<State,java.util.ArrayList<StateTransition>> stateGraph

    - #### maskList

          protected java.util.ArrayList<Event> maskList

  - ### Constructor Detail

    - #### StateMachine

          public StateMachine()

  - ### Method Detail

    - #### start

          protected void start(State state)

      start Define the start state of the state machine. Should be called from the start method of the feature's state machine.
      Parameters:
        `state` - The initial state.

    - #### addTransition

          public void addTransition(StateTransition transition)

      addTransition Adds a transition to the state machine.
      Parameters:
        `transition` - the transition to add.

    - #### consumeEvent

          public State consumeEvent(Event event)

      consumeEvent Executes a state transition and returns the new state. *
      Parameters:
        `event` - The event to consume
      Returns:
        The new state, or the current state if the current state does not have a matching event edge.

    - #### maskEvent

          public void maskEvent(Event event)

    - #### unMaskEvent

          public void unMaskEvent(Event event)

    - #### transition

          protected State transition(Event event)

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`