Re: test for default history content

[...]

> what if we define
>
> getTargetStates(stateList, defaultEntryContent)
>     allTargets = newOrderedSet
>     for state in stateList:
>          if isHistoryState(state):
>               if historyValue[state.id]:
>                    allTargets.union(historyValue[state.id])
>               else:
>
> allTargets.union(getTargetStates(state.transition.target))
>                   defaultHistoryContent[state.parent.id] =
> state.transition.content
>          else:
>              allTargets.add(state)
>
> If we do this, addDescendentStatesToEnter should never see a history
> state, so it can be simplified to:
>
> procedure addDescendantStatesToEnter(state,statesToEnter,statesForDefaultEntry, defaultHistoryContent):
>     if isCompoundState(state):
>         statesForDefaultEntry.add(state)
>         for s in getTargetStates(state.initial):
>            statesToEnter.add(s)
>            addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry)
>            addAncestorStatesToEnter(s, state, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
>     elif isParallelState(state):
>          for child in getChildStates(state):
>              if not statesToEnter.some(lambda s: isDescendant(s,child)):
>                 statesToEnter.add(child)
>                 addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
>
> Hi,

Please excuse the wait - only just found time this morning to test the
suggested changes.
After two small alterations, they work well.

It is important to remember that we call getTargetStates from several
places where we don't have a reference to defaultHistoryContent. Therefore,
the argument is optional and we need to test whether defaultHistoryContent
is null before trying to populate it.

Secondly, addDescendantStatesToEnter should call statesToEnter.add(state);
at the start and not do the statesToEnter.add() calls as per suggestion.
The way it is written above causes test 403c, 504 and 533 to fail. So the
final addDescendantStatesToEnter definition looks like this [1].

Best regards,
Zjnue

[1]

procedure addDescendantStatesToEnter(state,statesToEnter,statesForDefaultEntry,
defaultHistoryContent):
    statesToEnter.add(child)
    if isCompoundState(state):
        statesForDefaultEntry.add(state)
        for s in getTargetStates(state.initial):
           addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry)
           addAncestorStatesToEnter(s, state, statesToEnter,
statesForDefaultEntry, defaultHistoryContent)
    elif isParallelState(state):
         for child in getChildStates(state):
             if not statesToEnter.some(lambda s: isDescendant(s,child)):

addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry,
defaultHistoryContent)

Received on Tuesday, 1 April 2014 09:51:37 UTC