Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » How to get the elements of a chain(list) in a Collection
How to get the elements of a chain(list) in a Collection [message #89985] Tue, 09 September 2008 15:35 Go to next message
Pi is currently offline PiFriend
Messages: 12
Registered: July 2009
Junior Member
Hi,
I have the following problem, I would like to write a helper to get me all
the elements in a chain. The metamodel is that I have a process element
that can relate to other process. So it is possible to have a chain in the
model like process1 relates to proces2 which relates to process3 and so
on, so I would like to have all the processes in the chain as a
Collection, so that I can later on pass it as a parameter in a rule. I
tried the following code, but it only returns me the last element in the
chain ...

helper context processmap!Process def : getAllProcesses() :
OrderedSet(processmap!Process) =
self.relatesTo->iterate(process ; processes: OrderedSet(processmap!Process) =
OrderedSet {} |
if not(process.relatesTo->isEmpty()) then
(processes.append(process.getAllProcessesHelp()))
else processes.append(process)
endif
);

and my code I know for sure does not append also the first element in the
chain, meaning the self itself. I also know that probably my approach is
wrong as a process relates to only one other process, meaning that
self.relates to is not a Collection, so iteration over this is not a good
idea, but how otherwise to define a collection and to put the elements in
it?
Could somebody help me?
Thank you! Greets, Petko
Re: How to get the elements of a chain(list) in a Collection [message #90004 is a reply to message #89985] Tue, 09 September 2008 18:03 Go to previous messageGo to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 71
Registered: July 2009
Member
Hi,

Your approach to try to define a recursive helper is a good, like you
already noted the iterator is not a good idea:
helper context processmap!Process def : getAllProcesses() :
OrderedSet(processmap!Process) =
if self.relatesTo.oclIsUndefined() then
self.relatesTo.getAllProcesses().including(self)
else
OrderedSet{self}
endif;


Regards,

Alfons

self.relatesTo->iterate(process ; processes: OrderedSet(processmap!Process)
=
OrderedSet {} |
if not(process.relatesTo->isEmpty()) then
(processes.append(process.getAllProcessesHelp()))
else processes.append(process)
endif
);


" Petko" <petko_iv@abv.bg> schreef in bericht
news:1fd920dacac8c48827855146565c0dbd$1@www.eclipse.org...
> Hi,
> I have the following problem, I would like to write a helper to get me all
> the elements in a chain. The metamodel is that I have a process element
> that can relate to other process. So it is possible to have a chain in the
> model like process1 relates to proces2 which relates to process3 and so
> on, so I would like to have all the processes in the chain as a
> Collection, so that I can later on pass it as a parameter in a rule. I
> tried the following code, but it only returns me the last element in the
> chain ...
>
> helper context processmap!Process def : getAllProcesses() :
> OrderedSet(processmap!Process) =
> self.relatesTo->iterate(process ; processes:
> OrderedSet(processmap!Process) = OrderedSet {} |
> if not(process.relatesTo->isEmpty()) then
> (processes.append(process.getAllProcessesHelp()))
> else processes.append(process)
> endif
> );
>
> and my code I know for sure does not append also the first element in the
> chain, meaning the self itself. I also know that probably my approach is
> wrong as a process relates to only one other process, meaning that
> self.relates to is not a Collection, so iteration over this is not a good
> idea, but how otherwise to define a collection and to put the elements in
> it?
> Could somebody help me?
> Thank you! Greets, Petko
>
Re: How to get the elements of a chain(list) in a Collection [message #90019 is a reply to message #90004] Wed, 10 September 2008 09:40 Go to previous message
Pi is currently offline PiFriend
Messages: 12
Registered: July 2009
Junior Member
Thank you for the answer!!! It really helped, just a small thing, one
"not" has to be added :
if not(self.relatesTo.oclIsUndefined()) then ....
the recursive call has to be done only if there are further references
defined, meaning if they are not undefined.
10x once again for the answer,
Regards, Petko
Previous Topic:[ATL] Problems using UML2 models
Next Topic:[ATL] refininig and parameters passing
Goto Forum:
  


Current Time: Fri Apr 26 09:15:04 GMT 2024

Powered by FUDForum. Page generated in 0.03368 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top