public class SubStateMachineBuilder<StateId,Event>
extends java.lang.Object
StateMachineBuilder.get()
(for top
level state machines) or CompositeStateBuilder.getStateMachineBuilder()
(for composite states).
The following kind of transitions are supported:
addTransition
with the event parameter not null
. These transitions are explicitly
triggered with processEvent
and change the
state (or exit then enter the same state if the source and target state
are the same).
addInternalTransition
.
The event parameter cannot be null
. These transitions trigger an action
without exiting the current state.
addTransition
with the event parameter null
. These transitions are automatically
triggered after each successful transition. If guarded and the guard value
changes to true, it is cannot be checked automatically, only when the next
(internal or external) transition happens. It can also be triggered
explicitly with processEvent(null)
.
Modifier and Type | Method and Description |
---|---|
CompositeStateBuilder<StateId,Event> |
addCompositeState(StateId id)
Add a new composite state.
|
SubStateMachineBuilder<StateId,Event> |
addInternalTransition(StateId state,
Event event,
ITransitionAction<StateId,Event> action)
|
SubStateMachineBuilder<StateId,Event> |
addInternalTransition(StateId state,
Event event,
ITransitionAction<StateId,Event> action,
IGuard<StateId,Event> guard)
Add a new internal transition.
|
StateBuilder<StateId,Event> |
addState(StateId id)
Add a new state.
|
SubStateMachineBuilder<StateId,Event> |
addTransition(StateId fromState,
Event event,
ITransitionAction<StateId,Event> action,
StateId toState)
|
SubStateMachineBuilder<StateId,Event> |
addTransition(StateId fromState,
Event event,
ITransitionAction<StateId,Event> action,
StateId toState,
IGuard<StateId,Event> guard)
Add a new transition.
|
SubStateMachineBuilder<StateId,Event> |
setInitialState(StateId initialState)
Set the initial state of the state machine.
|
public SubStateMachineBuilder<StateId,Event> setInitialState(StateId initialState)
initialState
- The initial state of the state machine.public StateBuilder<StateId,Event> addState(StateId id)
Only one state with one ID is allowed. If another one with the same ID is attempted to be added, an exception is thrown.
id
- The identifier of the new state.DuplicateStateException
- If the state id already exists.public CompositeStateBuilder<StateId,Event> addCompositeState(StateId id)
Only one state with one id is allowed. If another one with the same ID is attempted to be added, an exception is thrown.
id
- The identifier of the new state.DuplicateStateException
- If the state id already exists.public SubStateMachineBuilder<StateId,Event> addTransition(StateId fromState, Event event, ITransitionAction<StateId,Event> action, StateId toState, IGuard<StateId,Event> guard)
null
. If event is
null
, that means it is a completion transition. Otherwise, it is a
normal transition.
For each state and event, only one transition is allowed, except if all transitions for that state and event are guarded. Warning: There is no guarantee that all guard checks are executed. The first transition where the guard returns true is executed.
Warning: There is no check that completion transitions won't cause an infinite loop.
fromState
- The initial state of the transition.event
- The event that triggers the transition. If null
, it is a
completion transition.action
- The action to be executed.toState
- The final state of the transition.DuplicateTransitionException
- If there is an ambiguous transition.{@link
- NoStateException} If either fromState of
toState does not exist.public SubStateMachineBuilder<StateId,Event> addTransition(StateId fromState, Event event, ITransitionAction<StateId,Event> action, StateId toState)
public SubStateMachineBuilder<StateId,Event> addInternalTransition(StateId state, Event event, ITransitionAction<StateId,Event> action, IGuard<StateId,Event> guard)
null
.state
- The initial state of the transition.event
- The event that triggers the transition.action
- The action to be executed.DuplicateTransitionException
- If there is already a transition
from the same state with the same event.{@link
- NoStateException} If either fromState of
toState does not exist.public SubStateMachineBuilder<StateId,Event> addInternalTransition(StateId state, Event event, ITransitionAction<StateId,Event> action)