Package org.zkoss.fsm
Class StateCtx<E,C,IN>
- java.lang.Object
-
- org.zkoss.fsm.StateCtx<E,C,IN>
-
- Direct Known Subclasses:
MacroStateCtx
public class StateCtx<E,C,IN> extends java.lang.Object
A context for a State in a StateMachine, holding returning and transition information.- Since:
- 6.0.0
- Author:
- simonpai
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
StateCtx.TransitionListener<IN,C>
-
Field Summary
Fields Modifier and Type Field Description protected StateMachine<E,C,IN>
_machine
protected java.util.Set<IN>
_minorReturners
protected java.util.Map<IN,StateCtx.TransitionListener<IN,C>>
_minorTransitionListeners
protected java.util.Map<IN,E>
_minorTransitions
protected boolean
_returnAll
protected java.util.Set<C>
_returners
protected java.util.Map<C,StateCtx.TransitionListener<IN,C>>
_transitionListeners
protected java.util.Map<C,E>
_transitions
-
Constructor Summary
Constructors Constructor Description StateCtx()
Creates a new state context
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StateCtx<E,C,IN>
addMinorRoute(IN input, E destination)
Add a transition for a character.StateCtx<E,C,IN>
addMinorRoute(IN input, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition for a character with callback.StateCtx<E,C,IN>
addMinorRoutes(E destination, IN... inputs)
Add multiple transitions for characters.StateCtx<E,C,IN>
addMinorRoutes(E destination, StateCtx.TransitionListener<IN,C> callback, IN... inputs)
Add multiple transitions for characters with a callback.StateCtx<E,C,IN>
addMinorTransition(IN input, E destination)
Add a transition for a character.StateCtx<E,C,IN>
addMinorTransition(IN input, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition for a character with a callbackStateCtx<E,C,IN>
addMinorTransitions(E destination, IN... inputs)
Add multiple transitions for charactersStateCtx<E,C,IN>
addMinorTransitions(E destination, StateCtx.TransitionListener<IN,C> callback, IN... inputs)
Add multiple transitions for characters with a callbackStateCtx<E,C,IN>
addReturningClasses(C... inputClasses)
Add an input class for returning to this stateStateCtx<E,C,IN>
addReturningClasses(java.util.Collection<C> collection)
Add multiple input classes for returning to this stateStateCtx<E,C,IN>
addReturningInputs(IN... inputs)
Add input characters for returning to this stateStateCtx<E,C,IN>
addReturningInputs(java.util.Collection<IN> collection)
Add input characters for returning to this stateStateCtx<E,C,IN>
addRoute(C inputClass, E destination)
Add a transition.StateCtx<E,C,IN>
addRoute(C inputClass, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition with callback.StateCtx<E,C,IN>
addRoutes(E destination, C... inputClasses)
Add multiple transitions.StateCtx<E,C,IN>
addRoutes(E destination, StateCtx.TransitionListener<IN,C> callback, C... inputClasses)
Add multiple transitions with a callback.StateCtx<E,C,IN>
addTransition(C inputClass, E destination)
Add a transition ruleStateCtx<E,C,IN>
addTransition(C inputClass, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition rule with a callbackStateCtx<E,C,IN>
addTransitions(E destination, C... inputClasses)
Add multiple transitionsStateCtx<E,C,IN>
addTransitions(E destination, StateCtx.TransitionListener<IN,C> callback, C... inputClasses)
Add multiple transitions with a callbackE
getDestination(IN input, C inputClass)
Returns the destination state upon meeting the character or the class.protected void
init()
Initialization method called at the constructorboolean
isLeaving(IN input, C inputClass)
Returns true if the machine is leaving this state upon meeting the character or the class.boolean
isReturning(IN input, C inputClass)
Returns true if this state returns to itself upon meeting the character or the class.boolean
isReturningAll()
Returns true if this state returns to itself by default, unless meeting specified characters or classes.protected void
onLand(IN input, C inputClass, E origin)
This method is called when the machine enters this stateprotected void
onLeave(IN input, C inputClass, E destination)
This method is called when the machine leaves this stateprotected void
onReject(IN input, C inputClass)
This method is called when the machine rejects the input on this stateprotected void
onReturn(IN input, C inputClass)
This method is called when the machine returns to the same stateprotected void
onStop(boolean endOfInput)
This method is called when the machine stops on this stateprotected StateCtx<E,C,IN>
setMaster(StateMachine<E,C,IN> master)
Sets the owner state machine.StateCtx<E,C,IN>
setReturningAll(boolean returnAll)
Set whether returns to this state upon meeting unspecified characters
-
-
-
Field Detail
-
_machine
protected StateMachine<E,C,IN> _machine
-
_returnAll
protected boolean _returnAll
-
_returners
protected final java.util.Set<C> _returners
-
_minorReturners
protected final java.util.Set<IN> _minorReturners
-
_transitionListeners
protected final java.util.Map<C,StateCtx.TransitionListener<IN,C>> _transitionListeners
-
_minorTransitionListeners
protected final java.util.Map<IN,StateCtx.TransitionListener<IN,C>> _minorTransitionListeners
-
-
Method Detail
-
setMaster
protected StateCtx<E,C,IN> setMaster(StateMachine<E,C,IN> master)
Sets the owner state machine.
-
init
protected void init()
Initialization method called at the constructor
-
addReturningClasses
public StateCtx<E,C,IN> addReturningClasses(C... inputClasses)
Add an input class for returning to this state- Returns:
- this state
-
addReturningClasses
public StateCtx<E,C,IN> addReturningClasses(java.util.Collection<C> collection)
Add multiple input classes for returning to this state- Returns:
- this state
-
addReturningInputs
public StateCtx<E,C,IN> addReturningInputs(IN... inputs)
Add input characters for returning to this state- Returns:
- this state
-
addReturningInputs
public StateCtx<E,C,IN> addReturningInputs(java.util.Collection<IN> collection)
Add input characters for returning to this state- Returns:
- this state
-
setReturningAll
public StateCtx<E,C,IN> setReturningAll(boolean returnAll)
Set whether returns to this state upon meeting unspecified characters- Returns:
- this state
-
addTransition
public StateCtx<E,C,IN> addTransition(C inputClass, E destination)
Add a transition rule- Returns:
- this state
-
addTransition
public StateCtx<E,C,IN> addTransition(C inputClass, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition rule with a callback- Returns:
- this state
-
addTransitions
public StateCtx<E,C,IN> addTransitions(E destination, C... inputClasses)
Add multiple transitions- Returns:
- this state
-
addTransitions
public StateCtx<E,C,IN> addTransitions(E destination, StateCtx.TransitionListener<IN,C> callback, C... inputClasses)
Add multiple transitions with a callback- Returns:
- this state
-
addRoute
public StateCtx<E,C,IN> addRoute(C inputClass, E destination)
Add a transition. Same asaddTransition(Object, Object)
, and only differs in return value.- Returns:
- destination state.
-
addRoute
public StateCtx<E,C,IN> addRoute(C inputClass, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition with callback. Same asaddTransition(Object, Object, TransitionListener)
, and only differs in return value.- Returns:
- destination state.
-
addRoutes
public StateCtx<E,C,IN> addRoutes(E destination, C... inputClasses)
Add multiple transitions. Same asaddTransitions(Object, Object...)
, and only differs in return value.- Returns:
- destination state.
-
addRoutes
public StateCtx<E,C,IN> addRoutes(E destination, StateCtx.TransitionListener<IN,C> callback, C... inputClasses)
Add multiple transitions with a callback. Same asaddTransitions(Object, TransitionListener, Object...)
, and only differs in return value.- Returns:
- destination state.
-
addMinorTransition
public StateCtx<E,C,IN> addMinorTransition(IN input, E destination)
Add a transition for a character.- Returns:
- this state
-
addMinorTransition
public StateCtx<E,C,IN> addMinorTransition(IN input, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition for a character with a callback- Returns:
- this state
-
addMinorTransitions
public StateCtx<E,C,IN> addMinorTransitions(E destination, IN... inputs)
Add multiple transitions for characters- Returns:
- this state
-
addMinorTransitions
public StateCtx<E,C,IN> addMinorTransitions(E destination, StateCtx.TransitionListener<IN,C> callback, IN... inputs)
Add multiple transitions for characters with a callback- Returns:
- this state
-
addMinorRoute
public StateCtx<E,C,IN> addMinorRoute(IN input, E destination)
Add a transition for a character. Same asaddMinorRoute(Object, Object)
, and only differs in return value.- Returns:
- destination state
-
addMinorRoute
public StateCtx<E,C,IN> addMinorRoute(IN input, E destination, StateCtx.TransitionListener<IN,C> callback)
Add a transition for a character with callback. Same asaddMinorTransition(Object, Object, TransitionListener)
, and only differs in return value.- Returns:
- destination state
-
addMinorRoutes
public StateCtx<E,C,IN> addMinorRoutes(E destination, IN... inputs)
Add multiple transitions for characters. Same asaddMinorTransitions(Object, Object...)
, and only differs in return value.- Returns:
- destination state
-
addMinorRoutes
public StateCtx<E,C,IN> addMinorRoutes(E destination, StateCtx.TransitionListener<IN,C> callback, IN... inputs)
Add multiple transitions for characters with a callback. Same asaddMinorTransitions(Object, TransitionListener, Object...)
, and only differs in return value.- Returns:
- destination state
-
isReturningAll
public boolean isReturningAll()
Returns true if this state returns to itself by default, unless meeting specified characters or classes.
-
isReturning
public boolean isReturning(IN input, C inputClass)
Returns true if this state returns to itself upon meeting the character or the class.
-
isLeaving
public boolean isLeaving(IN input, C inputClass)
Returns true if the machine is leaving this state upon meeting the character or the class.
-
getDestination
public E getDestination(IN input, C inputClass)
Returns the destination state upon meeting the character or the class.
-
onLand
protected void onLand(IN input, C inputClass, E origin)
This method is called when the machine enters this state
-
onReturn
protected void onReturn(IN input, C inputClass)
This method is called when the machine returns to the same state
-
onReject
protected void onReject(IN input, C inputClass)
This method is called when the machine rejects the input on this state
-
onLeave
protected void onLeave(IN input, C inputClass, E destination)
This method is called when the machine leaves this state
-
onStop
protected void onStop(boolean endOfInput)
This method is called when the machine stops on this state
-
-