How to get the elements of a chain(list) in a Collection [message #89985] |
Tue, 09 September 2008 15:35 |
Pi 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 |
Alfons Laarman 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
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03368 seconds