public class StateSimple.Trans
extends java.lang.Object
StateSimple.Trans
for each transition, which should be initialized with the destination state classes.
class MyState_A extends StateSimple { Trans cause_State1 = new Trans(MyState1.class); Trans trans1_State2 = new Trans(MyState_B.class) { (at)Override void action(EventObject ev) { ...any action } };The method
action(EventObject)
in the transition instance is optional.
The state should override the method StateSimple.checkTrans(EventObject)
which contains the check of all transition conditions
except for given StateSimple.Timeout
and StateSimple.TransJoin
. That transitions are selected without user code only because they are existing
as instances.
buildTransitionPath()
is invoked only on startup of the statemachine.
It creates the exitStates
and entryStates
-list.
StateSimple.aTransitions
array.
Modifier and Type | Field and Description |
---|---|
protected StateAction |
action
If an action is given, the condition should not contain an action itself.
|
protected StateSimple.Trans[] |
choice
More as one choice can be given if this transition is a choice-transition.
|
(package private) boolean |
doneAction
Set it to false on start of check this transition.
|
(package private) boolean |
doneEntry
Set it to false on start of check this transition.
|
(package private) boolean |
doneExit
Set it to false on start of check this transition.
|
(package private) int[] |
dst
All destination classes from constructor.
|
(package private) StateSimple[] |
entryStates
All states which's
StateSimple#entry(EventMsg2) have to be processed if the transition is fired. |
(package private) StateSimple[] |
exitStates
All states which's
StateSimple#exitTheState() have to be processed if the transition is fired. |
(package private) int |
ixCommonInStatePath
Index of the common state for this transition in the
StateSimple.statePath of any source state. |
(package private) StateSimple.Trans |
parent
It is null for a simple transition in a state.
|
int |
retTrans
Return value of the last used transition test.
|
(package private) java.lang.String |
transId
Identification String for the transition, for debug.
|
Constructor and Description |
---|
Trans(java.lang.Class<?>... dst)
This constructor is used to initialize a Transition instance maybe for a derived anonymous class
with null, one or more destination state of this transition
or as super constructor for derived classes if a priority should be given.
|
Trans(java.lang.String name,
int[] dstKeys)
This constructor should be used if the destination states are given from an outer algorithm.
|
Modifier and Type | Method and Description |
---|---|
protected void |
action(java.util.EventObject ev)
The non-overridden action executes the
action or returns 0 if it is not given. |
(package private) void |
buildTransitionPath()
Builds the transition path from given state to all dst states.
|
(package private) void |
doAction(java.util.EventObject ev,
int recurs)
Processes the action of the transition.
|
void |
doEntry(java.util.EventObject ev)
Entry in all states for this transition maybe with history entry.
|
void |
doExit()
Executes the exit from this state and all enclosing States to fire the transition.
|
StateSimple.Trans |
eventConsumed()
Set the state of transition execution to
EventConsumer.mEventConsumed and return this. |
void |
setAction(StateAction action)
Sets the action to this transition.
|
java.lang.String |
toString() |
public int retTrans
TransitionMethod
.final int[] dst
buildTransitionPath()
because they are processed in the exitStates
and entryStates
lists.protected StateAction action
protected StateSimple.Trans[] choice
action
of the state and the action
of the choice is executed one after another after exit() and before entry() only if the transition is fired.
If some choice are given, the choice should contain the destination state. The constructor of this transition have to be empty.StateSimple.Trans parent
StateSimple[] exitStates
StateSimple#exitTheState()
have to be processed if the transition is fired.int ixCommonInStatePath
StateSimple.statePath
of any source state. It is used to execute the exit()
of all nested source states.StateSimple[] entryStates
StateSimple#entry(EventMsg2)
have to be processed if the transition is fired.
The array is filled by reflection in the constructor of the state class. There the private Trans.BuildTransitionPath#buildEntryStates()
is invoked to fill the array. On doneEntry
the states in this array are entered.
For a simple transition the content of this array is simple, the order of the entry states from the last exitStates
.
For a fork transition to parallel states this array contains all entered states as a parallel fork. See an example:
statePath statePath statePath --+---------+----------+---------- 0 topState topState topState 1 StateC StateC StateC 1 StateAp StateAp StateAp StateAp is a StateParallel 2 StateA1 StateBp StateBp StateBp is a StateParallel 3 StateA11 StateB1 StateB2 4 StateB12 StateB25 5 StateB252The common state may be the StateC because the transition goes from a State inside stateC to the shown 3 destination states. Therefore the
#ixInStatePath
is initialized with [2, 2, 2]
.
stateC
found at statePath[2]
but only one time because it is the same for all state paths.
stateA1
is entered. After them StateBp
but only one time because it is the same twice.
stateA11
, then StateB1
, then StateB2
is entered.
StateB12
and StateB25
is entered.
StateB525
is entered.
0 1 2 3 4 5 6 ix in statePath +<---Cxy | top--->C +--->Ap --->|--->A1 | |--->Bp--->|--->B1--->B12 |--->B2--->B25--->B251
Cxy
may be the exit state, C
is the common state. The array contains:
Ap, A1, Bp, B1, B2, B12, B25, B251
java.lang.String transId
boolean doneExit
#doEntry(EventMsg2)
, #doAction(Trans, EventMsg2, int)
and doExit()
sets it to true.
If a #check(EventMsg2)
method has not invoked this methods, they are invoked from the StateSimple#_checkTransitions(EventMsg2)
.boolean doneAction
#doEntry(EventMsg2)
, #doAction(Trans, EventMsg2, int)
and doExit()
sets it to true.
If a #check(EventMsg2)
method has not invoked this methods, they are invoked from the StateSimple#_checkTransitions(EventMsg2)
.boolean doneEntry
#doEntry(EventMsg2)
, #doAction(Trans, EventMsg2, int)
and doExit()
sets it to true.
If a #check(EventMsg2)
method has not invoked this methods, they are invoked from the StateSimple#_checkTransitions(EventMsg2)
.public Trans(java.lang.Class<?>... dst)
choice
-transitions.dst
- null, one ore more destination classes.
If the dst is null or not given, the transition is a inner-state-transition. If it fires the StateSimple.exit()
and the entry is not executed.
If more as one dst is given this is a fork transition to more as one state, which should be states in parallel composite states.public Trans(java.lang.String name, int[] dstKeys)
dstKeys
- public void setAction(StateAction action)
action(EventObject)
.
This action is used only if the method action
is not overridden.action
- public StateSimple.Trans eventConsumed()
EventConsumer.mEventConsumed
and return this.
This method should be used in StateSimple.checkTrans(EventObject)
if an event is the trigger:
QOverride public Trans selectTransition(EventObject ev) { if(ev == expectedEv) return myTrans.eventConsumed(); ...
void buildTransitionPath()
protected void action(java.util.EventObject ev)
action
or returns 0 if it is not given.ev
- eventfinal void doAction(java.util.EventObject ev, int recurs)
parent
- The transition before this choice or null on State-transitionev
- The given event.recurs
- recursion count. throws IllegalArgumentException if > 20public final void doExit()
StateCompositeFlat
the StateComposite.stateAct
of its StateSimple.compositeState()
will be used
to invoke StateSimple.exitTheState(int)
always.public final void doEntry(java.util.EventObject ev)
StateSimple.checkTrans(EventObject)
routine
with the selected transition. The routine sets the flag doneEntry
. If the method is not invoked by the application
it will be invoked in the StateSimple._checkTransitions(EventObject)
.
The states will be entered in the order from outer to inner state
and for all parallel states then from outer to inner one in each parallel both, using the entryStates
.
It regards history entry: StateDeepHistory
, StateShallowHistory
.ev
- The data of the event can be used by entry actions.public java.lang.String toString()
toString
in class java.lang.Object