Interface State<O,S extends Enum<S>,E extends Enum<E>>

Type Parameters:
O - the class of the instance owning the finite state machine instance
S - the state enumeration type uniquely identifying a state in the state machine
E - the event enumeration type uniquely identifying the event sent to the state machine
All Superinterfaces:
Comparable<State<O,S,E>>

public interface State<O,S extends Enum<S>,E extends Enum<E>> extends Comparable<State<O,S,E>>
The state abstraction of a hierarchical finite state machine.
  • Method Details

    • compareTo

      default int compareTo(@NotNull @NotNull State<O,S,E> other)
      Specified by:
      compareTo in interface Comparable<O>
    • id

      S id()
      Gets the id of this state.
      Returns:
      the id of this state.
    • hasHistory

      boolean hasHistory()
      Return true if the state has history active.
      Returns:
      flag indicating if the state has history
    • isInitial

      boolean isInitial()
      Return true if the state is an initial state.
      Returns:
      flag indicating if the state is an initial state
    • isFinal

      default boolean isFinal()
      Return true if the state is a final state. A state is final if no transitions are leaving it.
      Returns:
      flag indicating if the state is final
    • isComposite

      default boolean isComposite()
      Return true if the state contains substates. If true, the state cannot be initial or final.
      Returns:
      flag indicating if the state is composite.
    • executeEntryAction

      void executeEntryAction(O owner, Event<E> event)
      Execute the entry action associated with the state if defined.
      Parameters:
      owner - instance owning the finite state machine
      event - the event triggering the execution of the action if defined
    • executeExitAction

      void executeExitAction(O owner, Event<E> event)
      Execute the exit action associated with the state if defined.
      Parameters:
      owner - instance owning the finite state machine
      event - the event triggering the execution of the action if defined
    • substates

      Set<State<O,S,E>> substates()
      Return the list of substates.
      Returns:
      the set of substates or an empty list if none is defined.
    • transitions

      Set<Transition<O,S,E>> transitions()
      Return the list of transitions starting from this state.
      Returns:
      the set of transitions or an empty list if none is defined
    • localTransitions

      Set<Transition<O,S,E>> localTransitions()
      Return the list of local or self transitions starting from this state. Self-transitions do not trigger entry or exit actions.
      Returns:
      the set of self-transitions or an empty list if none is defined
    • hasEntryAction

      default boolean hasEntryAction()
      Return true if the state has an entry action.
      Returns:
      flag indicating if the state has an entry action
    • entryAction

      BiConsumer<O,Event<E>> entryAction()
      Return the entry action of the state.
      Returns:
      the action if defined otherwise null
    • hasExitAction

      default boolean hasExitAction()
      Return true if the state has an exit action.
      Returns:
      flag indicating if the state has an exit action
    • exitAction

      BiConsumer<O,Event<E>> exitAction()
      Return the exit action of the state.
      Returns:
      the action if defined otherwise null
    • getStateFor

      State<O,S,E> getStateFor(S stateId)
      Return the state with the given state identifier.
      Parameters:
      stateId - identifier of the state looked for
      Returns:
      the requested state if found otherwise null
    • initialState

      State<O,S,E> initialState()
      Return the direct substate being an initial state.
      Returns:
      the direct substate flagged with initial otherwise null
    • initialStates

      Deque<State<O,S,E>> initialStates()
      Return the state machine's default initial state.
      Returns:
      the ordered hierarchy of states being an initial state if defined otherwise an empty list. The head contains the root state, the tail contains the deepest substate
    • description

      String description()
      Return the human-readable description of the state.
      Returns:
      the description of the state if defined otherwise null
    • entryActionDescription

      String entryActionDescription()
      Return the human-readable description for the entry action of the state.
      Returns:
      the description of the entry action for the state if defined otherwise null
    • exitActionDescription

      String exitActionDescription()
      Return the human-readable description for the exit action of the state.
      Returns:
      the description of the exit action for state if defined otherwise null
    • getHierarchyFor

      default Deque<State<O,S,E>> getHierarchyFor(State<O,S,E> substate)
      Return the list of all substates including this state and the given substate to reach the given substate. The hierarchy includes the boundary states. If not found, the list is empty.
      Parameters:
      substate - substate to look for
      Returns:
      the ordered hierarchy of states to reach the substate if found otherwise an empty list. The head contains the root state, the tail contains the searched substate
    • findBy

      default Optional<State<O,S,E>> findBy(@NotNull S stateId)
      Return the state with the given identifier.
      Parameters:
      stateId - identifier of the state to be found
      Returns:
      the state if found