public abstract class FSMContext extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected boolean |
_debugFlag
When this flag is set to
true , this class will
print out debug messages. |
protected PrintStream |
_debugStream
Write debug output to this stream.
|
protected String |
_name
The FSM name.
|
protected State |
_previousState
Stores which state a transition left.
|
protected State |
_state
The current state.
|
protected Stack<State> |
_stateStack
This stack is used to store the current state when a push
transition is taken.
|
protected String |
_transition
The current transition name.
|
Modifier | Constructor and Description |
---|---|
protected |
FSMContext(State initState)
Creates a finite state machine context for the given
initial state.
|
Modifier and Type | Method and Description |
---|---|
void |
addStateChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.
|
void |
clearState()
Places the current state into the previous state sets
the current state to
null . |
void |
emptyStateStack()
Empties the state stack.
|
abstract void |
enterStartState()
Starts the finite state machine running by executing the
initial state's entry actions.
|
boolean |
getDebugFlag()
When debug is set to
true , the state machine
will print messages to the console. |
PrintStream |
getDebugStream()
Writes the debug output to this stream.
|
String |
getName()
Returns the FSM name.
|
State |
getPreviousState()
If this FSM is in transition, then returns the previous
state which the last transition left.
|
String |
getTransition()
If this FSM is in transition, then returns the transition
name.
|
boolean |
isInTransition()
Returns
true if this FSM is in a transition and
false otherwise. |
void |
popState()
Sets the previous state to the current state and pops
the top state off the stack and places it into the
current state.
|
void |
pushState(State state)
Pushes the current state on top of the state stack and
sets the current state to
state . |
void |
removeStateChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener for the state change
property.
|
void |
setDebugFlag(boolean flag)
Turns debug output on if
flag is true and
off if flag is false . |
void |
setDebugStream(PrintStream stream)
Sets the debug output stream to the given value.
|
void |
setName(String name)
Sets the FSM name.
|
void |
setState(State state)
Sets the current state to the given value.
|
protected transient String _name
protected transient State _state
null
while in
transition.protected transient String _transition
protected transient State _previousState
null
.protected transient Stack<State> _stateStack
protected transient boolean _debugFlag
true
, this class will
print out debug messages.protected transient PrintStream _debugStream
protected FSMContext(State initState)
initState
- the finite state machine's start state.public abstract void enterStartState()
public String getName()
public boolean getDebugFlag()
true
, the state machine
will print messages to the console.true
if debug output is generated.public PrintStream getDebugStream()
public boolean isInTransition()
true
if this FSM is in a transition and
false
otherwise.true
if this FSM is in a transition and
false
otherwise.public State getPreviousState() throws NullPointerException
null
.NullPointerException
public String getTransition()
public void setName(String name)
name
- The finite state machine name.public void setDebugFlag(boolean flag)
flag
is true
and
off if flag
is false
.flag
- true
to turn debuggin on and
false
to turn debugging off.public void setDebugStream(PrintStream stream)
stream
- The debug output stream.public void setState(State state)
state
- The current state.public void clearState()
null
.public void pushState(State state)
state
.state
- The new current state.NullPointerException
- if state
is null
.public void popState() throws EmptyStackException
EmptyStackException
- if the state stack is empty.public void emptyStateStack()
public void addStateChangeListener(PropertyChangeListener listener)
listener
is null
,
no exception is thrown and no action is taken.listener
- The PropertyChangeListener to be added.public void removeStateChangeListener(PropertyChangeListener listener)
listener
was added more than once
to the same event source, it will be notified one less
time after being removed. If listener
is
null
or was never added, no exception is thrown
and no action is taken.listener
- The PropertyChangeListener to be removed.Copyright © 2020. All rights reserved.