StateId
- The type used for referencing states.Event
- The type used for referencing events.public class StateMachineBuilder<StateId,Event>
extends java.lang.Object
IStateMachine
. To create a state machine, follow these steps:
StateMachineBuilder
.
get()
method to obtain an instance of
SubStateMachineBuilder
.
StateBuilder
which can be
acquired by the SubStateMachineBuilder.addState(Object)
method.
CompositeStateBuilder
which can be acquired by the SubStateMachineBuilder.addCompositeState(Object)
method. Use CompositeStateBuilder.getStateMachineBuilder()
to
acquire a SubStateMachineBuilder
instance for the sub state machine.
create()
to create an instance of IStateMachine
.
Each state and event has a unique identifier represented by a respective Id types
(which are typically enum
types, but they can be any type that can be
used as a key in a HashMap
).
When a transition takes place in a state machine created by this class
(by calling the IStateMachine.processEvent(Object)
method), the actions are taken place in the following order:
Note: The created class (and the entire library) is not thread-safe.
This means that in order to use it from within multiple threads, calls to any
methods (typically processEvent
)
must be synchronized.
Constructor and Description |
---|
StateMachineBuilder() |
Modifier and Type | Method and Description |
---|---|
IStateMachine<StateId,Event> |
create()
Create the state machine.
|
SubStateMachineBuilder<StateId,Event> |
get()
Return the builder for the top level state machine.
|
public SubStateMachineBuilder<StateId,Event> get()
public IStateMachine<StateId,Event> create()
get()
after this results in a builder for a completely new state machine.