Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Concat collection
Concat collection [message #899617] Wed, 01 August 2012 15:10 Go to next message
Matthias N is currently offline Matthias N
Messages: 65
Registered: June 2012
Member
Hi,
I have a class A which can have multiple references to class B

What I want to do is, to concatenate all referenced names.

When I use the following command
self.VVCase__vvSubject->asSequence().name

I get:
'name1'
'name2'
'name3'


But what I want to have sth like this:
'name1, name2, name3'


How can I achive this with OCL ?! I found an example with "->iterate()", however my OCL sais "cannot find operation iterate() for the type (OrderedSet(VVCase)).


thanks
Re: Concat collection [message #899622 is a reply to message #899617] Wed, 01 August 2012 15:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

I often use iterate for exactly this purpose. It works.

Without seeing your code there is no chance of telling why it doesn't
work for you.

Regards

Ed Willink


On 01/08/2012 16:10, Matthias N wrote:
> Hi,
> I have a class A which can have multiple references to class B
>
> What I want to do is, to concatenate all referenced names.
>
> When I use the following command
>
> self.VVCase__vvSubject->asSequence().name
>
> I get:
>
> 'name1'
> 'name2'
> 'name3'
>
>
> But what I want to have sth like this:
> 'name1, name2, name3'
>
>
> How can I achive this with OCL ?! I found an example with
> "->iterate()", however my OCL sais "cannot find operation iterate()
> for the type (OrderedSet(VVCase)).
>
>
> thanks
Re: Concat collection [message #899678 is a reply to message #899617] Wed, 01 August 2012 18:49 Go to previous messageGo to next message
Matthias N is currently offline Matthias N
Messages: 65
Registered: June 2012
Member
I am using the GMF Framework with OCL. Should "iterate" work ?!
Re: Concat collection [message #899711 is a reply to message #899678] Thu, 02 August 2012 04:36 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

And what did my reply say?

Yes. You have to provide an example to get further help ...

Regards

Ed Willink


On 01/08/2012 19:49, Matthias N wrote:
> I am using the GMF Framework with OCL. Should "iterate" work ?!
Re: Concat collection [message #899773 is a reply to message #899711] Thu, 02 August 2012 10:03 Go to previous messageGo to next message
Matthias N is currently offline Matthias N
Messages: 65
Registered: June 2012
Member
Okay, I modelled the following with Ecore

+--------+
| root   |
+--------+
    <>
    |
    | 
+--------+        dogs * +-------+
| Person | <>----------- |  Dog  |
+--------+               +-------+

I populated the model with 3 dogs.

I use the interactive OCL console, e.g. context Person: self.dogs->size() results to 3.

When I input
self.dogs->
, auto-completion gives me
includes
includesAll
including
indexOf
insertAt
intersection
isEmpty
isUnique

no iterate ;(
Re: Concat collection [message #899788 is a reply to message #899617] Thu, 02 August 2012 11:20 Go to previous messageGo to next message
Matthias N is currently offline Matthias N
Messages: 65
Registered: June 2012
Member
finally I got it.
Don't know why the auto-completion is not showing iterate, however it works:

dogs->iterate(iterator: Dog; result : String = '' | result.concat(iterator.name))
Re: Concat collection [message #899813 is a reply to message #899773] Thu, 02 August 2012 12:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

Which release are you using?

Completion assist was ropy in Indigo. It's much better in Juno. Works
for me in Juno.

[Not even JDT is perfect on Completion assist; it is only a guide of
likely candidates.]

Regards

Ed Willink


On 02/08/2012 11:03, Matthias N wrote:
> Okay, I modelled the following with Ecore
>
>
> +--------+
> | root |
> +--------+
> <>
> |
> | +--------+ dogs * +-------+
> | Person | <>----------- | Dog |
> +--------+ +-------+
>
> I populated the model with 3 dogs.
>
> I use the interactive OCL console, e.g. context Person:
> self.dogs->size() results to 3.
>
> When I input self.dogs->, auto-completion gives me
>
> includes
> includesAll
> including
> indexOf
> insertAt
> intersection
> isEmpty
> isUnique
>
> no iterate ;(
Re: Concat collection [message #900246 is a reply to message #899813] Mon, 06 August 2012 07:18 Go to previous message
Matthias N is currently offline Matthias N
Messages: 65
Registered: June 2012
Member
Okay, I am using helios
Previous Topic:Referencing to OCL constraint
Next Topic:Acceleo invoking a Java Service Wrapping OCL
Goto Forum:
  


Current Time: Wed Oct 22 22:33:04 GMT 2014

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

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