public final class FSM
extends java.lang.Object
FSM
is a complete implementation of a finite state
machine (a.k.a. deterministic finite automaton). The FSM is
represented as a Map
, so clients will need to provide a
properly formatted Map
object to initialize the FSM.
The recommended way to build this Map
is to use the
FSMBuilder
class, which provides an API abstraction for
building the FSM data structure.
An FSM
returns an FSMStateInfo
every time a
client class asks for the next or previous state. The interpretation
of the FSMStateInfo
object's contents is left to the
client class's implementation.
The FSM
encapsulates fairly complex behavior. An
FSM
:
FSM
has halted. By definition, a halted FSM is one that has
completed its final state (and a particular FSM specification may contain
more than one final state). A final state is said to be "completed" when
its activity (represented by the Step
) has finished and Step's
Traversable
does not specify an exit transition that leaves the
final state.This means that it is possible to transition out of a final state into a non-final state or even another final state. The computational model for deterministic finite automata (DFA) allows for this, so this implementation simply follows suit. From a practical standpoint, most FSM's should need only one final state, and implementors should strive to have only one final state (with no transitions out of it) unless there is a specific feature that cannot be implemented otherwise.
The design of this class and its methods are based on the concepts behind the UML State Machine diagram, the UML Activity diagram, and the computational model of a deterministic finite automaton.
FSMBuilder
,
Step
,
Traversable