Enum State

  • All Implemented Interfaces:
    Serializable, Comparable<State>

    public enum State
    extends Enum<State>
    The State captures the main functionality of the state machine. It represents a specific state in the state machine, and holds all transitions possible from a specific state.

    The state transition diagram is as follows:

               +--[a]--> W --[b]--> Y --[e]---+
               |                    ^         |
       Initial-+                    |         |
               |                    |         +--> (Z)-----[g]---> Terminal
               +--[c]--> X --[b]----+         |
                         |                    |
                         +--------[d]---------+
     
    • Enum Constant Detail

      • Terminal

        public static final State Terminal
        The terminal state in the state machine.
      • InvalidTransition

        public static final State InvalidTransition
        Special state returned by the State.transition(...) function when attempting an illegal state transition.
      • Z

        public static final State Z
        State 'Z'.
      • Y

        public static final State Y
        State 'Y'.
      • X

        public static final State X
        State 'X'.
      • W

        public static final State W
        State 'W'.
      • Initial

        public static final State Initial
        The initial state from which all state sequences start.
    • Method Detail

      • values

        public static State[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (State c : State.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static State valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • isTerminal

        public boolean isTerminal()
        Checks if this state is a terminal state. A terminal state has no outgoing transitions.
      • transition

        public State transition​(EventType evt)
        Gets the state after transitioning from this state based on the given event. If the transition is valid, this returns the new state, and if this transition is illegal, it returns [[InvalidTransition]].
        Parameters:
        evt - The event that defined the transition.
        Returns:
        The new state, or [[InvalidTransition]].
      • randomTransition

        public EventTypeAndState randomTransition​(Random rnd)
        Picks a random transition, based on the probabilities of the outgoing transitions of this state.
        Parameters:
        rnd - The random number generator to use.
        Returns:
        A pair of (transition event , new state).
      • randomInvalidTransition

        public EventType randomInvalidTransition​(Random rnd)
        Returns an event type that, if applied as a transition on this state, will result in an illegal state transition.
        Parameters:
        rnd - The random number generator to use.
        Returns:
        And event type for an illegal state transition.