Class StateMachine.Builder

  • Enclosing class:
    StateMachine

    public static final class StateMachine.Builder
    extends Object
    Builder that builds a StateMachine.
    • Method Detail

      • addState

        public StateMachine.Builder addState​(Enum stateEnum,
                                             String description)
        Adds a state with name and description.
        Parameters:
        stateEnum - enumeration indicating the state
        description - description of the state
        Returns:
        the builder
        Throws:
        RuntimeException - if the state was already added
      • setInitialState

        public StateMachine.Builder setInitialState​(Enum stateToSet)
        Parameters:
        stateToSet - the initial state for StateMachine
        Returns:
        the builder
        Throws:
        RuntimeException - if the initial state was not added first
      • addTransition

        public StateMachine.Builder addTransition​(Enum from,
                                                  Enum to,
                                                  String description)
        Adds a transition with description.
        Parameters:
        from - from state name
        to - to state name
        description - description of the transition
        Returns:
        the builder
        Throws:
        RuntimeException - if either from or to state was not added, or the same transition was already added
      • build

        public StateMachine build()
        Builds and returns the StateMachine.
        Returns:
        the StateMachine
        Throws:
        RuntimeException - if an initial state was not set