Home » Modeling » M2T (model-to-text transformation) » [Xpand/Xtend] Deleting elements from one List affects the elements on another List(How to delete elements from List in the right way?)
[Xpand/Xtend] Deleting elements from one List affects the elements on another List [message #662411] |
Wed, 30 March 2011 11:02  |
Eclipse User |
|
|
|
Hello all,
I have a problem when trying to delete elements from one List.
Here is my scenario: I have two List, 'ancestors' and 'orderedList'. The first one contains, temporally, elements collected during a loop iteration. The second one is made to contain, permanently, all 'ancestors' values. And when the rule 'removeAllElements()' deletes elements from 'ancestors', the elements from 'orderedList' are, magically, deleted too.
The code of each rule is:
Xpand rule to obtain full hierarchy tree
«DEFINE fullyHierarchyOUList(List unorderedList, List orderedList) FOR gormas_model»
«LET (List) {} AS ancestors»
«FOREACH unorderedList AS unorderedNode»
«REM» Delete values from previous iteration «ENDREM»
«ancestors.removeAllElements() -> ""»
«LET (List)unorderedNode AS unorderedNodeAsList»
«REM» Search for ancestors in recursive way «ENDREM»
«searchParent(unorderedNodeAsList, ancestors, unorderedList.reject(e|e==unorderedNodeAsList))»
«REM» Add ancestors to final List «ENDREM»
«orderedList.add(ancestors)»
«ENDLET» «REM» End of LET (List)unorderedNode AS unorderedNodeList «ENDREM»
«ENDFOREACH»
«ENDLET» «REM» End of LET (List) {} AS ancestors «ENDREM»
«ENDDEFINE»
Xtend function to delete elements from List
List removeAllElements(List objectList) : {
if objectList.size > 0 then (
objectList.remove(objectList.last()) ->
removeAllElements(objectList)
)
};
Xtend recursive function to search for ancestors
Void searchParent(List[OrganizationalUnit] lastCheckedNodeAsList, List ancestors, List unorderedList): {
ancestors.add(((OrganizationalUnit)lastCheckedNodeAsList.first())) ->
if lastCheckedNodeAsList.size > 1 then
searchParent( ((List)(unorderedList.select(e|((List) e).first() == lastCheckedNodeAsList.last()).first())), ancestors, unorderedList.reject(e|e==lastCheckedNodeAsList) )
};
With these entries:
unorderedList = [[University], [Center, University], [Department, University], [Laboratoty, Department]]
orderedList = []
The required results are:
orderedList = [[University], [Center, University], [Department, University], [Laboratoty, Department, University]]
However, the results obtained are:
orderedList = [[Laboratory, Department,University], [Laboratory, Department,University], [Laboratory, Department,University], [Laboratory, Department,University]]
Somebody understands it? This issue is driving me crazy.
Regards.
|
|
| | |
Goto Forum:
Current Time: Mon Jul 07 02:21:22 EDT 2025
Powered by FUDForum. Page generated in 0.27194 seconds
|