Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Simple Question about OCL indexOf operation
Simple Question about OCL indexOf operation [message #1078837] Sat, 03 August 2013 17:14 Go to next message
Archevo tarek is currently offline Archevo tarekFriend
Messages: 21
Registered: July 2013
Junior Member
Hi,

I'm using this following request:

self->asSet()->closure(eContents()->select(oclIsKindOf(model::YYY) or oclIsKindOf(model::ZZZ)).oclAsType(EObject))->select(a:EObject| a.oclIsKindOf(model::xxx) and a.oclAsType(model::xxx).name='XX')->collect(a:EObject| a.eContainer())->asSet()

It gets the container element, of the element with kind 'xxx' having the name 'XX'.

I want to use the operation indexOf to get the position of the element 'XX' inside the sequence of elements in the container element.

Thanks.
Re: Simple Question about OCL indexOf operation [message #1078856 is a reply to message #1078837] Sat, 03 August 2013 17:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your 'solution' seems incredibly complex and suspect.

Given that you can do such things with closure, why does indexOf cause
you difficulties?

Regards

Ed Willink

On 03/08/2013 18:14, Archevo tarek wrote:
> Hi,
>
> I'm using this following request:
>
> self->asSet()->closure(eContents()->select(oclIsKindOf(model::YYY) or
> oclIsKindOf(model::ZZZ)).oclAsType(EObject))->select(a:EObject|
> a.oclIsKindOf(model::xxx) and
> a.oclAsType(model::xxx).name='XX')->collect(a:EObject|
> a.eContainer())->asSet()
>
> It gets the container element, of the element with kind 'xxx' having
> the name 'XX'.
>
> I want to use the operation indexOf to get the position of the element
> 'XX' inside the sequence of elements in the container element.
>
> Thanks.
Re: Simple Question about OCL indexOf operation [message #1078875 is a reply to message #1078856] Sat, 03 August 2013 18:32 Go to previous messageGo to next message
Archevo tarek is currently offline Archevo tarekFriend
Messages: 21
Registered: July 2013
Junior Member
Hi ed,
Thanks for your answer.
I told you i'm novice in OCL, and i'm learning by examples. I found this solution with closure after long tests thanks to your assistance. I know that indexOf needs an object as an argument. The elements in the collection given by 'collect' are EObject elements. The collect operation gets the container element inside which other elements may exist. I just want to get the index (position) of the element with kind 'xxx' having the name 'XX' inside the collection. That's what i need.
I'm steel testing and trying some requests using the indexOf() operation, for example this one in the Xtext Console:

self->asSet()->closure(oclContents()->select(oclIsKindOf(model::Activity) or oclIsKindOf(model::ExtensibleElement)))
->select(a:model::Activity| a.oclIsKindOf(model::Assign) and a.oclAsType(model::Assign).name='Assign2')
->collect(a:model::Assign| a.oclContainer())->asOrderedSet()->indexOf(model::Assign)

Results:
Missing value for 'indexOf'


Any help.
Thanks in advance.
Re: Simple Question about OCL indexOf operation [message #1080253 is a reply to message #1078875] Mon, 05 August 2013 17:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If I rewrite your expression to be more readable

self->closure(oclContents())
->select(oclIsKindOf(model::Activity) or
oclIsKindOf(model::ExtensibleElement))
->select(oclIsKindOf(model::Assign) and
oclAsType(model::Assign).name='Assign2')
->collect(oclContainer())
->asOrderedSet()
->indexOf(model::Assign)

we can see two funnies.

a) the source of the indexOf is an asOrderedSet() suggesting that the
ordeting will be indeterminate, and so the index of limited utility.

b) the argument is a type so it is unlikely that you will have any
content whose identity is equal to their type

The navigation makes very little sense to me, and so I suggest that you
have failed to understand what problem you want to solve, or the
metamodel that you are using is really not fit for purpose.

Regards

Ed Willink


On 03/08/2013 19:32, Archevo tarek wrote:
> Hi ed,
> Thanks for your answer.
> I told you i'm novice in OCL, and i'm learning by examples. I found
> this solution with closure after long tests thanks to your assistance.
> I know that indexOf needs an object as an argument. The elements in
> the collection given by 'collect' are EObject elements. The collect
> operation gets the container element inside which other elements may
> exist. I just want to get the index (position) of the element with
> kind 'xxx' having the name 'XX' inside the collection. That's what i
> need.
> I'm steel testing and trying some requests using the indexOf()
> operation, for example this one in the Xtext Console:
>
>
> self->asSet()->closure(oclContents()->select(oclIsKindOf(model::Activity)
> or oclIsKindOf(model::ExtensibleElement)))
> ->select(a:model::Activity| a.oclIsKindOf(model::Assign) and
> a.oclAsType(model::Assign).name='Assign2')
> ->collect(a:model::Assign|
> a.oclContainer())->asOrderedSet()->indexOf(model::Assign)
>
> Results:
> Missing value for 'indexOf'
>
>
> Any help.
> Thanks in advance.
>
Re: Simple Question about OCL indexOf operation [message #1080275 is a reply to message #1080253] Mon, 05 August 2013 18:24 Go to previous messageGo to next message
Archevo tarek is currently offline Archevo tarekFriend
Messages: 21
Registered: July 2013
Junior Member
Hi ed,
Thanks for answering me.

a) The asOrderedSet() is just for the indexOf() operation which work on a OrderedSet or a Sequence.
In the obtained container element, elements are for sure having a determined sequencing since it is selected from an instance of the metamodel which i have not modified yet, then, the index here is very important for my needs.

b) you are absolutely wright for type.

The expression i sended in my previuos post works fine (thanks to your assistance) and it gives the good result. May be it is a bit complex and this is due i think to the metamodel i'm working on it (i posted in my previous posts) which is very complex.



Re: Simple Question about OCL indexOf operation [message #1080292 is a reply to message #1080275] Mon, 05 August 2013 18:52 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your computation is a closure over a set. There is no determinism to the
ordering.

Regards

Ed Willink


On 05/08/2013 19:24, Archevo tarek wrote:
> Hi ed,
> Thanks for answering me.
>
> a) The asOrderedSet() is just for the indexOf() operation which work
> on a OrderedSet or a Sequence. In the obtained container element,
> elements are for sure having a determined sequencing since it is
> selected from an instance of the metamodel which i have not modified
> yet, then, the index here is very important for my needs.
>
> b) you are absolutely wright for type.
>
> The expression i sended in my previuos post works fine (thanks to your
> assistance) and it gives the good result. May be it is a bit complex
> and this is due i think to the metamodel i'm working on it (i posted
> in my previous posts) which is very complex.
>
>
>
>
Previous Topic:IndexOf()!!
Next Topic:UML2ECORE via adapter
Goto Forum:
  


Current Time: Fri Apr 19 20:01:17 GMT 2024

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

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

Back to the top