public abstract class StateComposite extends StateCompositeFlat implements InfoAppend
stateAct
.StateSimple.PlugStateSimpleToGenState, StateSimple.Timeout, StateSimple.Trans, StateSimple.TransChoice, StateSimple.TransJoin
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
isActive
Stores whether this composite state is active.
|
protected int |
maxStateSwitchesInLoop |
(package private) StateSimple |
stateAct |
static java.lang.String |
version
Version, history and license.
|
aSubstates, stateDefault
compositeState, ctEntry, dateLastEntry, durationLast, enclState, entry, evTimeout, exit, ixCompositeState_inStatePath, mEventConsumed, mEventDonotRelinquish, mEventNotConsumed, millisectimeout, modeTrans, mRunToComplete, mStateEntered, mStateLeaved, mTransit, notTransit, stateId, stateMachine, statePath, transTimeout
Constructor and Description |
---|
StateComposite()
The constructor of any StateComposite checks the class for inner classes which are the states.
|
StateComposite(java.lang.String name,
StateMachine stateMachine,
StateSimple[] aSubstates)
Only used for the
StateMachine.stateTop
and as special constructor to build a state machine from other data. |
Modifier and Type | Method and Description |
---|---|
private void |
assembleDstState(java.lang.StringBuilder uStateNext,
StateSimple stateAct1) |
private static int |
doEntryDeepHistory(StateSimple state,
java.util.EventObject ev)
Execution routine of enter the deep history.
|
protected int |
entryDeepHistory(java.util.EventObject ev)
This method is called from
StateSimple.Trans.doEntry(EventObject) if the history state should be entered and all history states
should be entered in sub states. |
int |
entryShallowHistory(java.util.EventObject ev)
This method should be called from outside if the history state should be entered but the default state of any
sub state should be entered.
|
java.lang.CharSequence |
getStatePath()
Gets the path to this state.
|
java.lang.CharSequence |
infoAppend(java.lang.StringBuilder u)
Appends or returns tan information about the instance.
|
boolean |
isInState(StateSimple state)
Check whether this composite state has the given state as direct actual sub state
|
private void |
printStateSwitchInfo(StateSimple statePrev,
java.util.EventObject evTrans,
int cont) |
(package private) int |
processEvent(java.util.EventObject evP)
Processes the event for the states of this composite state.
|
java.lang.String |
toString()
Returns the state Id and maybe some more debug information.
|
(package private) void |
XXXexitTheState(int level)
Exits first the actual sub state (and that exits its actual sub state), after them this state is exited.
|
addState, buildStatePathSubstates, createTransitionListSubstate, entryDefaultState, prepareTransitionsSubstate, stateDefault
_checkTransitions, auxInfo, buildStatePath, checkTrans, compositeState, createTransitionList, enclState, entry, entryTheState, exit, exitTheState, getName, isInState, isTimeout, prepareTransitions, setAuxInfo, setEntryAction, setExitAction, statePath
public static final java.lang.String version
processEvent(EventObject)
more simple because enclosing non-StateComposite transitions are checked in StateSimple.
printStateSwitchInfo(StateSimple, EventObject, int)
StateParallel
. More simple, more flexibility.
org.vishia.stateMachine.StateCompositeBase
, changed concept:
Nested writing of states, less code, using reflection for missing instances and data.
EventConsumer
yet. Especially a timer event needs a destination
which is this class.
#entry(EventMsg2)
and the #entryAction(EventMsg2)
should get the event
from the transition. See StateSimpleBase
.
#setDefaultState(StateSimpleBase)
StateCompositeFlat.entryDefaultState()
is package private now, it regards requirements of StateParallelBase
.
StateSimpleBase#entry(int)
if the instance is this type.
protected int maxStateSwitchesInLoop
boolean isActive
#exitTheState()
routine if exit of the enclosing state is processed.StateSimple stateAct
public StateComposite(java.lang.String name, StateMachine stateMachine, StateSimple[] aSubstates)
StateMachine.stateTop
and as special constructor to build a state machine from other data. See org.vishia.stateMGen.StateMGen.public StateComposite()
StateSimple
is instantiated and stored both in the StateMachine.stateMap
to find all states by its class.hashCode
and in StateCompositeFlat.aSubstates
for debugging only.
#buildStatePathSubstates()
is invoked to store the state path in all states.
Then StateCompositeFlat.createTransitionListSubstate(int)
is invoked which checks the transition of all states recursively.
Therewith all necessary data for the state machines's processing are created on construction.StateMachine#StateMachine()
,
StateComposite#buildStatePathSubstates(StateComposite, int)
,
StateSimple#buildStatePath(StateComposite)
,
StateCompositeFlat.createTransitionListSubstate(int)
,
StateSimple#createTransitionList()
public final boolean isInState(StateSimple state)
state
- Only states of the own composite are advisable. It is checked in compile time
with the strong type check with the generic type of state.protected final int entryDeepHistory(java.util.EventObject ev)
StateSimple.Trans.doEntry(EventObject)
if the history state should be entered and all history states
should be entered in sub states.StateSimple.entry(EventObject)
, especially bit StateSimpleBase#mRunToComplete
.private static final int doEntryDeepHistory(StateSimple state, java.util.EventObject ev)
StateSimple.ixCompositeState_inStatePath
.
entryDeepHistory(EventObject)
will be called recursively.
entryDeepHistory(EventObject)
will be called for all parallel states.
state
- The stored current state used as history.ev
- entryDeepHistory(EventObject)
public final int entryShallowHistory(java.util.EventObject ev)
isProcessed
- The bit StateSimpleBase#mEventConsumed
is supplied to return it.StateSimpleBase#mRunToComplete
is set by user.int processEvent(java.util.EventObject evP)
processEvent(EventObject)
which calls this method recursively.
StateSimpleBase#mRunToComplete
that invocation is repeated in a loop, to call
the transition of the new state too. But if the event was consumed by the last invocation, it is not supplied again
in the loop, the event parameter is set to null instead. It means only conditional transitions are possible.
This behavior is conform with the UML definition.
maxStateSwitchesInLoop
. This exception occurs
if the user stateMachine conditions are faulty only.
StateSimple._checkTransitions(EventObject)
of this state is invoked but only if the event is not processed
or the state contains non-event triggered (conditional) transitions. Last one is signified by the StateSimple.modeTrans
.
StateSimple.processEvent(EventObject)
which is overridden by StateParallel.processEvent(EventObject)
too to provide one method for event processing for all state kinds with the necessary different handling.
StateSimpleBase#mEventConsumed
as result of the inside called StateSimple._checkTransitions(EventObject)
to remove the event for further usage in an enclosing state processing.
StateSimpleBase#mRunToComplete
is not delivered because it has no sense outside.
StateSimpleBase#mRunToComplete
processEvent
in class StateSimple
evP
- The event.StateSimple
private void printStateSwitchInfo(StateSimple statePrev, java.util.EventObject evTrans, int cont)
private void assembleDstState(java.lang.StringBuilder uStateNext, StateSimple stateAct1)
void XXXexitTheState(int level)
StateSimple#exitTheState()
which invokes the maybe application overridden StateSimple.exit()
routine.public java.lang.CharSequence getStatePath()
StateSimple
StateSimple.stateId
of all enclosing states
separated with a dot and at least this stateId.
For example "topStateName.compositeState.thisState".getStatePath
in class StateSimple
public java.lang.CharSequence infoAppend(java.lang.StringBuilder u)
InfoAppend
StringBuilder u = new StringBulder(1000); u.append(something_else); myInstance.infoAppend(u); //uses this interface u.append(some_more); System.out.append(u); //output the information String savedInfo = u.toString(); //save permanent.Implementing pattern
QOverride public infoAppend(StringBuilder u) { if(u == null){ u = new StringBuilder(); } //it can be null! u.append(special_information).append(": ").append(somewhatElse); return u; }Contiguity with toString: It uses the same information, assembled in a StringBuilder:
QOverride public String toString(){ return infoAppend(null).toString()); }
infoAppend
in interface InfoAppend
infoAppend
in class StateSimple
u
- if not null then the info is appended to u, u is returned.
public java.lang.String toString()
StateSimple
toString
in class StateSimple
Object.toString()