Interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>

All Known Implementing Classes:
StateBuilderImpl

public interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
  • Method Details

    • getState

      Enum<S> getState()
    • withEnterAction

      StateBuilder<S,C,D> withEnterAction(BiConsumer<C,D> action, Label label)
      Register an action that will be executed upon entering this state. This action is ONLY executed when you enter the action from another state. I.e., on a transition A -> B, B's enter action would be triggered. However, if you transition between the same state, so e.g. B -> B, then this enter action will NOT trigger. If you wish to trigger an action on "self enter", then use withSelfEnterAction(BiConsumer).
      Parameters:
      action - the action that will be executed
      label - a human-readable label, which is ONLY meant for documentation purposes. E.g., PlantUmlVisitor uses it when it generates state diagrams.
    • withEnterAction

      default StateBuilder<S,C,D> withEnterAction(BiConsumer<C,D> action)
    • withInitialEnterAction

      StateBuilder<S,C,D> withInitialEnterAction(BiConsumer<C,D> action, Label label)
      Register an action that will be executed upon entering this state the very first time only. Note that any "regular" enter actions, as registered through withEnterAction(BiConsumer), will always be executed, including the very first time you enter the state. The initial enter action will always be executed first. Example: You have a state B that has registered an initial enter action and a "regular" enter action and your application makes the following transitions: A -> B -> C -> B -> D I.e., from the state A, you enter B for the very first time (given some event, not shown and not important for this example). Since this is the very first time you enter B the initial enter action will be executed first (if there is one of course), followed by the "regular" enter action (if there is one). The next transition between C and back to B is no longer the first time you enter the state B and as such, ONLY the "regular" enter action (if there is one) will be executed. Also remember that if you go from B -> B that doesn't trigger the enter/exit actions, which is why, in the above example, have to "fully" leave B and then come back via C again in order to trigger the enter actions.
      Parameters:
      action -
      Returns:
    • withInitialEnterAction

      default StateBuilder<S,C,D> withInitialEnterAction(BiConsumer<C,D> action)
    • withSelfEnterAction

      StateBuilder<S,C,D> withSelfEnterAction(BiConsumer<C,D> action, Label label)
      Register an action that will trigger when you transition to/from the same state. I.e., this action would trigger when you transitioned from B -> B but not A -> B.
      Parameters:
      action -
      Returns:
    • withSelfEnterAction

      default StateBuilder<S,C,D> withSelfEnterAction(BiConsumer<C,D> action)
    • withExitAction

      StateBuilder<S,C,D> withExitAction(BiConsumer<C,D> action, Label label)
      Register an action that will be executed upon exiting this state.
    • withExitAction

      default StateBuilder<S,C,D> withExitAction(BiConsumer<C,D> action)
    • withStateTimeout

      StateBuilder<S,C,D> withStateTimeout()
      Set the maximum time we allow to stay in this state. When this duration has passed and we are still in this state, the event StateTimeoutEvent will be fired and given to the state machine. If there are no registered transitions associated with that event for this state, then TODO - yeah, what do we want to happen. Perhaps just call the onUnhandledEvent or something? so that there is no difference between this one and everything else.
      Returns:
    • transitionToSelf

      EventBuildStep<S,C,D> transitionToSelf()
    • transitionTo

      EventBuildStep<S,C,D> transitionTo(S state)
    • build

      State build()