|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.util.CloneableObject
org.jboss.util.state.DefaultStateMachineModel
A default implementation of a state machine model.
Accepting to acceptable state mappings are backed up by a HashMap and HashSets.
Implements clonable so that the model can be used as a prototype. Nested containers are cloned, so that changes will not effect the master or other clones.
Nested Class Summary | |
protected static class |
DefaultStateMachineModel.Entry
A container for entiries in the state acceptable map. |
Nested classes inherited from class org.jboss.util.CloneableObject |
CloneableObject.Cloneable |
Field Summary | |
protected Map |
acceptingMap
The mapping from State to Entry. |
protected DefaultStateMachineModel.Entry |
current
The mapping entry for the current state. |
protected DefaultStateMachineModel.Entry |
initial
The mapping entry for the initial state. |
Constructor Summary | |
DefaultStateMachineModel()
Construct a new DefaultStateMachineModel. |
Method Summary | |
Set |
acceptableStates(State state)
Return an immutable set of the acceptable states for a given accepting state. |
Set |
addState(State state)
Add a final state. |
Set |
addState(State state,
Set acceptable)
Add a non-final state. |
Set |
addState(State state,
State acceptable)
|
Set |
addState(State state,
State[] acceptable)
Add a non-final state. |
StringBuffer |
appendPrettyString(StringBuffer buff,
String prefix)
Appends a pretty representation of the object to the given buffer. |
void |
clear()
Clear all accepting state mappings and reset the initial and current state to null. |
Object |
clone()
Clone the object via Object.clone() . |
boolean |
containsState(State state)
Check if a give state is contained in the model. |
boolean |
equals(Object obj)
|
State |
getCurrentState()
Get the current state. |
protected DefaultStateMachineModel.Entry |
getEntry(State state)
Get an entry from the map. |
State |
getInitialState()
Return the initial state which the state machine should start in. |
State |
getMappedState(State state)
Returns the state object mapped for the given state value. |
boolean |
isMappedState(State state)
Determins if there is a mapping for the given state object. |
protected DefaultStateMachineModel.Entry |
putEntry(State state,
Set acceptable)
Put a new entry into the map. |
Set |
removeState(State state)
Remove a state from the model. |
void |
setCurrentState(State state)
Set the current state. |
void |
setInitialState(State state)
Set the initial state. |
Set |
states()
Return an immutable set of the accepting states. |
String |
toString()
|
protected void |
updateAcceptableMapping(State state,
boolean remove)
Update acceptable mappings. |
Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Map acceptingMap
protected DefaultStateMachineModel.Entry initial
protected DefaultStateMachineModel.Entry current
Constructor Detail |
public DefaultStateMachineModel()
Method Detail |
public StringBuffer appendPrettyString(StringBuffer buff, String prefix)
PrettyString.Appendable
appendPrettyString
in interface PrettyString.Appendable
buff
- The buffer to use while making pretty.prefix
- The string which all lines of the output must be prefixed with.
public String toString()
public boolean equals(Object obj)
protected DefaultStateMachineModel.Entry getEntry(State state)
state
- The state of the entry; must not be null.protected DefaultStateMachineModel.Entry putEntry(State state, Set acceptable)
public boolean isMappedState(State state)
StateMachine.Model
isMappedState
in interface StateMachine.Model
state
- The state with the value of the bound state to check for;
must not be null.
public State getMappedState(State state)
StateMachine.Model
Since states with the same value are equivlent, this provides access to the actual state instance which is bound in the model.
getMappedState
in interface StateMachine.Model
state
- The state with the value of the bound state to return;
null will return false.
public Set addState(State state, Set acceptable)
StateMachine.Model
Existing acceptable states will be replaced by the given states.
Acceptable states which are not registered as accepting states will be added as final states.
If the acceptable set is null, then the added state will be final.
Note, states are added based on the valid states which can be transitioned to from the given state, not on the states which accept the given state.
For example, if adding state A which accepts B and C, this means that when the machine is in state A, it will allow transitions to B or C and not from C to A or B to A (unless of course a state mapping is setup up such that C and B both accept A).
addState
in interface StateMachine.Model
state
- The accepting state; must not be null.acceptable
- The valid acceptable states; must not contain null elements.public Set addState(State state, State[] acceptable)
StateMachine.Model
addState
in interface StateMachine.Model
state
- The accepting state; must not be null.acceptable
- The valid acceptable states; must not contain null elements.StateMachine.Model.addState(State,Set)
public Set addState(State state, State acceptable)
public Set addState(State state)
StateMachine.Model
Note, if the given state implements StateMachine.Acceptable
then
the final determiniation of its finality will be unknown until
runtime.
addState
in interface StateMachine.Model
state
- The final state; must not be null.public void setInitialState(State state)
StateMachine.Model
Does not need to validate the state, StateMachine
will
handle those details.
setInitialState
in interface StateMachine.Model
state
- The initial state; must not be null.public State getInitialState()
StateMachine.Model
getInitialState
in interface StateMachine.Model
public void setCurrentState(State state)
StateMachine.Model
Does not need to validate the state, StateMachine
will
handle those details.
setCurrentState
in interface StateMachine.Model
state
- The current state; must not be null.public State getCurrentState()
StateMachine.Model
getCurrentState
in interface StateMachine.Model
public boolean containsState(State state)
StateMachine.Model
containsState
in interface StateMachine.Model
state
- The state to look for.
public Set removeState(State state)
StateMachine.Model
removeState
in interface StateMachine.Model
state
- The state to remove.
protected void updateAcceptableMapping(State state, boolean remove)
state
- The state value to update or removeremove
- True to remove the state from all mappings.public Set states()
StateMachine.Model
states
in interface StateMachine.Model
public Set acceptableStates(State state)
StateMachine.Model
acceptableStates
in interface StateMachine.Model
state
- The accepting state to get acceptable states for; must not be null.
public void clear()
StateMachine.Model
clear
in interface StateMachine.Model
public Object clone()
CloneableObject
Object.clone()
. This will return
and object of the correct type, with all fields shallowly
cloned.
clone
in interface CloneableObject.Cloneable
clone
in class CloneableObject
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |