public class DeterministicStateMachine extends java.lang.Object implements StateMachine
SynchronizedStateMachine
Modifier and Type | Field and Description |
---|---|
protected FsmLogger |
logger
The logger.
|
INITIAL_STATE_NAME
Constructor and Description |
---|
DeterministicStateMachine(java.lang.String name)
Create the object.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(StateListener listener)
Add a new listener.
|
void |
addListener(TransitionListener listener)
Add a new listener.
|
void |
addPreprocessor(Preprocessor preprocessor)
Add a new preprocessor.
|
void |
addState(State state)
Add a new state.
|
void |
addTransition(Transition transition)
Add a new transition.
|
void |
close()
Finish processing of the events and free all allocated resources.
|
boolean |
easterEgg()
Each software product should contain at least one easter egg.
|
State |
getActiveState()
Get the currently active state.
|
java.util.Set<State> |
getActiveStates()
Get the currently active states.
|
java.lang.String |
getName()
Get the name of the processor.
|
java.util.Set<State> |
getStates()
Get all defined states.
|
protected Transition |
getTransition(State state,
Event event)
Get transition of a specified event type defined for a state.
|
java.util.Set<Transition> |
getTransitions()
Get all defined transitions.
|
boolean |
isInFinalState()
Is the active state a final state?
|
Event |
process(Event event)
Process the event.
|
void |
setStartState(State state)
Set the start state.
|
void |
start()
Building of the processor is finished, prepare it to the events
processing.
|
java.lang.String |
toString() |
protected final FsmLogger logger
public DeterministicStateMachine(java.lang.String name)
name
- the name of the state machinepublic void setStartState(State state) throws FsmException
StateMachine
setStartState
in interface StateMachine
state
- the stateFsmException
StateMachine.start()
,
Processor.process(Event)
public void start() throws FsmException
Processor
start
in interface Processor
start
in interface StateMachine
FsmException
- if something failsProcessor.close()
public void close()
Processor
Processor.close()
should be
avoided. The behavior is not defined and may cause unpredictable
behavior, e.g. NullPointerException
.close
in interface java.lang.AutoCloseable
close
in interface Processor
close
in interface StateMachine
Processor.start()
public void addState(State state) throws FsmException
StateMachine
addState
in interface StateMachine
state
- the stateFsmException
- if something failspublic void addTransition(Transition transition) throws FsmException
StateMachine
addTransition
in interface StateMachine
transition
- the transitionFsmException
- if something failspublic void addPreprocessor(Preprocessor preprocessor)
StateMachine
addPreprocessor
in interface StateMachine
preprocessor
- the preprocessorProcessor.process(Event)
,
StateMachine.start()
,
StateMachine.close()
public void addListener(StateListener listener)
StateMachine
addListener
in interface StateMachine
listener
- the listenerpublic void addListener(TransitionListener listener)
StateMachine
addListener
in interface StateMachine
listener
- the listenerpublic State getActiveState()
StateMachine
getActiveState
in interface StateMachine
StateMachine.getActiveStates()
public java.util.Set<State> getActiveStates()
StateMachine
getActiveStates
in interface StateMachine
StateMachine.getActiveState()
public Event process(Event event) throws FsmException
Processor
process
in interface Processor
event
- the input eventFsmException
- if something failspublic java.util.Set<State> getStates()
StateMachine
getStates
in interface StateMachine
public java.util.Set<Transition> getTransitions()
StateMachine
getTransitions
in interface StateMachine
protected Transition getTransition(State state, Event event)
state
- the state, it must be defined in the state machineevent
- the eventpublic boolean isInFinalState()
StateMachine
isInFinalState
in interface StateMachine
public java.lang.String toString()
toString
in class java.lang.Object
public boolean easterEgg()
Copyright 2012-2013 Michal Turek, AnotherFSM.