Package io.hektor.fsm.builder.impl
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()getState()booleanisFinal()isFinal(boolean value) booleanisInital()isInital(boolean value) transitionTo(S state) withEnterAction(BiConsumer<C, D> action, Label label) Register an action that will be executed upon entering this state.withExitAction(BiConsumer<C, D> action, Label label) Register an action that will be executed upon exiting this state.withInitialEnterAction(BiConsumer<C, D> action, Label label) Register an action that will be executed upon entering this state the very first time only.withSelfEnterAction(BiConsumer<C, D> action, Label label) Register an action that will trigger when you transition to/from the same state.Set the maximum time we allow to stay in this state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.hektor.fsm.builder.StateBuilder
withEnterAction, withExitAction, withInitialEnterAction, withSelfEnterAction
-
Constructor Details
-
StateBuilderImpl
-
StateBuilderImpl
-
-
Method Details
-
getState
-
withEnterAction
Register an action that will be executed upon entering this state.- Specified by:
withEnterActionin interfaceStateBuilder<S extends Enum<S>,C extends Context, D extends Data> - Parameters:
action- the action that will be executedlabel- a human-readable label, which is ONLY meant for documentation purposes. E.g.,PlantUmlVisitoruses it when it generates state diagrams.- Returns:
-
withInitialEnterAction
Description copied from interface:StateBuilderRegister an action that will be executed upon entering this state the very first time only. Note that any "regular" enter actions, as registered throughStateBuilder.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 -> DI.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:
withInitialEnterActionin interfaceStateBuilder<S extends Enum<S>,C extends Context, D extends Data> - Returns:
-
withSelfEnterAction
Description copied from interface:StateBuilderRegister 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:
withSelfEnterActionin interfaceStateBuilder<S extends Enum<S>,C extends Context, D extends Data> - Returns:
-
withExitAction
Register an action that will be executed upon exiting this state.- Specified by:
withExitActionin interfaceStateBuilder<S extends Enum<S>,C extends Context, D extends Data> - Returns:
-
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:
withStateTimeoutin interfaceStateBuilder<S extends Enum<S>,C extends Context, D extends Data> - Returns:
-
transitionToSelf
- Specified by:
transitionToSelfin interfaceStateBuilder<S extends Enum<S>,C extends Context, D extends Data>
-
transitionTo
- Specified by:
transitionToin interfaceStateBuilder<S extends Enum<S>,C extends Context, D extends Data>
-
build
-
isInital
-
isInital
public boolean isInital() -
isFinal
-
isFinal
public boolean isFinal()
-