Class StateBuilderImpl<S extends Enum<S>,C extends Context,D extends Data>

java.lang.Object
io.hektor.fsm.builder.impl.StateBuilderImpl<S,C,D>
All Implemented Interfaces:
StateBuilder<S,C,D>

public class StateBuilderImpl<S extends Enum<S>,C extends Context,D extends Data> extends Object implements StateBuilder<S,C,D>
Author:
jonas@jonasborjesson.com
  • Constructor Details

    • StateBuilderImpl

      public StateBuilderImpl(S state)
    • StateBuilderImpl

      public StateBuilderImpl(S state, boolean isTransient)
  • Method Details

    • getState

      public S getState()
      Specified by:
      getState in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
    • withEnterAction

      public StateBuilderImpl<S,C,D> withEnterAction(BiConsumer<C,D> action, Label label)
      Register an action that will be executed upon entering this state.
      Specified by:
      withEnterAction in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
      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.
      Returns:
    • withInitialEnterAction

      public StateBuilderImpl<S,C,D> withInitialEnterAction(BiConsumer<C,D> action, Label label)
      Description copied from interface: StateBuilder
      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 StateBuilder.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.
      Specified by:
      withInitialEnterAction in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
      Returns:
    • withSelfEnterAction

      public StateBuilderImpl<S,C,D> withSelfEnterAction(BiConsumer<C,D> action, Label label)
      Description copied from interface: StateBuilder
      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.
      Specified by:
      withSelfEnterAction in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
      Returns:
    • withExitAction

      public StateBuilderImpl<S,C,D> withExitAction(BiConsumer<C,D> action, Label label)
      Register an action that will be executed upon exiting this state.
      Specified by:
      withExitAction in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
      Returns:
    • withStateTimeout

      public StateBuilderImpl<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.
      Specified by:
      withStateTimeout in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
      Returns:
    • transitionToSelf

      public EventBuildStep<S,C,D> transitionToSelf()
      Specified by:
      transitionToSelf in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
    • transitionTo

      public EventBuildStep<S,C,D> transitionTo(S state)
      Specified by:
      transitionTo in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
    • build

      public State build()
      Specified by:
      build in interface StateBuilder<S extends Enum<S>,C extends Context,D extends Data>
    • isInital

      public StateBuilderImpl<S,C,D> isInital(boolean value)
    • isInital

      public boolean isInital()
    • isFinal

      public StateBuilderImpl<S,C,D> isFinal(boolean value)
    • isFinal

      public boolean isFinal()