Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » fastest way of accessing position, predecessor, successor of EMf list elements
fastest way of accessing position, predecessor, successor of EMf list elements [message #415008] Wed, 28 November 2007 10:58 Go to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
Hi, Everybody.
I tried several ways to derive position, predecessor, and successor of
lists in earlier projects.

What is the best way doing this?

I remember starting with the EObject, finding its containing feature,
geting the EList like this, and then looking it through.


Is there a faster, easier way?

Best, Philipp
Re: fastest way of accessing position, predecessor, successor of EMf list elements [message #415018 is a reply to message #415008] Wed, 28 November 2007 12:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050802060707060002050308
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Philipp,

So you're doing something like this?

List<?> values =
(List<?>)eObject.eContainer().eGet(eObject.eContainmentFeature());
int index = values.indexOf(eObject);

And then incrementing or decrementing index and checking it abounds the
0 or value.size()?


Philipp W. Kutter wrote:
> Hi, Everybody.
> I tried several ways to derive position, predecessor, and successor of
> lists in earlier projects.
>
> What is the best way doing this?
>
> I remember starting with the EObject, finding its containing feature,
> geting the EList like this, and then looking it through.
>
>
> Is there a faster, easier way?
>
> Best, Philipp


--------------050802060707060002050308
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Philipp,<br>
<br>
So you're doing something like this?<br>
<blockquote>List&lt;?&gt; values =
(List&lt;?&gt;)eObject.eContainer().eGet(eObject.eCo ntainmentFeature()); <br>
int index = values.indexOf(eObject);<br>
</blockquote>
And then incrementing or decrementing index and checking it abounds the
0 or value.size()?<br>
<br>
<br>
Philipp W. Kutter wrote:
<blockquote cite="mid:fijhi2$evv$1@build.eclipse.org" type="cite">Hi,
Everybody.
<br>
I tried several ways to derive position, predecessor, and successor of
<br>
lists in earlier projects.
<br>
<br>
What is the best way doing this?
<br>
<br>
I remember starting with the EObject, finding its containing feature,
geting the EList like this, and then looking it through.
<br>
<br>
<br>
Is there a faster, easier way?
<br>
<br>
Best, Philipp
<br>
</blockquote>
<br>
</body>
</html>

--------------050802060707060002050308--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: fastest way of accessing position, predecessor, successor of EMf list elements [message #415039 is a reply to message #415018] Wed, 28 November 2007 14:58 Go to previous messageGo to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
Yes, exactly. I use OCL for it:

parent.elements->indexOf(self)


I somehow feel, this is not the optimal way...

Best, Philipp


Ed Merks wrote:
> Philipp,
>
> So you're doing something like this?
>
> List<?> values =
> (List<?>)eObject.eContainer().eGet(eObject.eContainmentFeature());
> int index = values.indexOf(eObject);
>
> And then incrementing or decrementing index and checking it abounds the
> 0 or value.size()?
>
>
> Philipp W. Kutter wrote:
>> Hi, Everybody.
>> I tried several ways to derive position, predecessor, and successor of
>> lists in earlier projects.
>>
>> What is the best way doing this?
>>
>> I remember starting with the EObject, finding its containing feature,
>> geting the EList like this, and then looking it through.
>>
>>
>> Is there a faster, easier way?
>>
>> Best, Philipp
>
Re: fastest way of accessing position, predecessor, successor of EMf list elements [message #415040 is a reply to message #415039] Wed, 28 November 2007 15:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Philipp,

This sounds little more like
eObject.eContainer().eContents().indexOf(eObject) but I don't know OCL...


Philipp W. Kutter wrote:
> Yes, exactly. I use OCL for it:
>
> parent.elements->indexOf(self)
>
>
> I somehow feel, this is not the optimal way...
>
> Best, Philipp
>
>
> Ed Merks wrote:
>> Philipp,
>>
>> So you're doing something like this?
>>
>> List<?> values =
>> (List<?>)eObject.eContainer().eGet(eObject.eContainmentFeature());
>> int index = values.indexOf(eObject);
>>
>> And then incrementing or decrementing index and checking it abounds
>> the 0 or value.size()?
>>
>>
>> Philipp W. Kutter wrote:
>>> Hi, Everybody.
>>> I tried several ways to derive position, predecessor, and successor of
>>> lists in earlier projects.
>>>
>>> What is the best way doing this?
>>>
>>> I remember starting with the EObject, finding its containing
>>> feature, geting the EList like this, and then looking it through.
>>>
>>>
>>> Is there a faster, easier way?
>>>
>>> Best, Philipp
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: fastest way of accessing position, predecessor, successor of EMf list elements [message #415051 is a reply to message #415040] Wed, 28 November 2007 16:50 Go to previous messageGo to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
> This sounds little more like
> eObject.eContainer().eContents().indexOf(eObject) but I don't know OCL...

Would your version really work? Once you are at the eContainer, you
first need to select the correct many feature, and then get the indexOf.

eObject in my example is accessible as "self" and can be ommitted,
"parent" in my example is an opposite of a containment, thus it replaces
your eContainer(). Then, elements is my many-feature, of which I know I
am one of the elements in the list. The "->" is needed for all
collection operations, like indexOf(..), instead of the ".".


BUT my real question is, whether we can do it quicker. As I do it now,
it sounds very inefficient.

Best, Philipp
>
>
> Philipp W. Kutter wrote:
>> Yes, exactly. I use OCL for it:
>>
>> parent.elements->indexOf(self)
>>
>>
>> I somehow feel, this is not the optimal way...
>>
>> Best, Philipp
>>
>>
>> Ed Merks wrote:
>>> Philipp,
>>>
>>> So you're doing something like this?
>>>
>>> List<?> values =
>>> (List<?>)eObject.eContainer().eGet(eObject.eContainmentFeature());
>>> int index = values.indexOf(eObject);
>>>
>>> And then incrementing or decrementing index and checking it abounds
>>> the 0 or value.size()?
>>>
>>>
>>> Philipp W. Kutter wrote:
>>>> Hi, Everybody.
>>>> I tried several ways to derive position, predecessor, and successor of
>>>> lists in earlier projects.
>>>>
>>>> What is the best way doing this?
>>>>
>>>> I remember starting with the EObject, finding its containing
>>>> feature, geting the EList like this, and then looking it through.
>>>>
>>>>
>>>> Is there a faster, easier way?
>>>>
>>>> Best, Philipp
>>>
Re: fastest way of accessing position, predecessor, successor of EMf list elements [message #415054 is a reply to message #415051] Wed, 28 November 2007 16:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Philipp,

Comments below.

Philipp W. Kutter wrote:
>
>> This sounds little more like
>> eObject.eContainer().eContents().indexOf(eObject) but I don't know
>> OCL...
>
> Would your version really work? Once you are at the eContainer, you
> first need to select the correct many feature, and then get the indexOf.
You never stated explicitly you want to get other objects only in the
same feature, but certainly this approach would let you get a contained
sibling from a different feature. I just don't know what
parent.elements does and thought it might be like eObject.eContents().
It might be more like parent.getElements().
>
> eObject in my example is accessible as "self" and can be ommitted,
> "parent" in my example is an opposite of a containment, thus it
> replaces your eContainer(). Then, elements is my many-feature, of
> which I know I am one of the elements in the list. The "->" is needed
> for all collection operations, like indexOf(..), instead of the ".".
>
>
> BUT my real question is, whether we can do it quicker. As I do it now,
> it sounds very inefficient.
A contained child doesn't now the index at which it's contained (and it
would be kind of costly to maintain that), so indexOf is the best way to
find that. I can't think of a faster way...
>
> Best, Philipp
>>
>>
>> Philipp W. Kutter wrote:
>>> Yes, exactly. I use OCL for it:
>>>
>>> parent.elements->indexOf(self)
>>>
>>>
>>> I somehow feel, this is not the optimal way...
>>>
>>> Best, Philipp
>>>
>>>
>>> Ed Merks wrote:
>>>> Philipp,
>>>>
>>>> So you're doing something like this?
>>>>
>>>> List<?> values =
>>>> (List<?>)eObject.eContainer().eGet(eObject.eContainmentFeature());
>>>> int index = values.indexOf(eObject);
>>>>
>>>> And then incrementing or decrementing index and checking it abounds
>>>> the 0 or value.size()?
>>>>
>>>>
>>>> Philipp W. Kutter wrote:
>>>>> Hi, Everybody.
>>>>> I tried several ways to derive position, predecessor, and
>>>>> successor of
>>>>> lists in earlier projects.
>>>>>
>>>>> What is the best way doing this?
>>>>>
>>>>> I remember starting with the EObject, finding its containing
>>>>> feature, geting the EList like this, and then looking it through.
>>>>>
>>>>>
>>>>> Is there a faster, easier way?
>>>>>
>>>>> Best, Philipp
>>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: fastest way of accessing position, predecessor, successor of EMf list elements [message #415076 is a reply to message #415054] Wed, 28 November 2007 21:23 Go to previous message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
>>> This sounds little more like
>>> eObject.eContainer().eContents().indexOf(eObject) but I don't know
>>> OCL...
>>
>> Would your version really work? Once you are at the eContainer, you
>> first need to select the correct many feature, and then get the indexOf.
> You never stated explicitly you want to get other objects only in the
> same feature, but certainly this approach would let you get a contained
> sibling from a different feature. I just don't know what
> parent.elements does and thought it might be like eObject.eContents().
> It might be more like parent.getElements().

No no, my version runs perfectly. In Ocl you use "elements", not the
getter. At least Christian Damus did so in his examples.

By the way, the eContainer(), e.t.c. stuff is only available in OCL, if
you are explicitly inheriting from EObject in your models.


> A contained child doesn't now the index at which it's contained (and it
> would be kind of costly to maintain that), so indexOf is the best way to
> find that. I can't think of a faster way...
Ok, thanks.

Best, Philipp


>>
>> Best, Philipp
>>>
>>>
>>> Philipp W. Kutter wrote:
>>>> Yes, exactly. I use OCL for it:
>>>>
>>>> parent.elements->indexOf(self)
>>>>
>>>>
>>>> I somehow feel, this is not the optimal way...
>>>>
>>>> Best, Philipp
>>>>
>>>>
>>>> Ed Merks wrote:
>>>>> Philipp,
>>>>>
>>>>> So you're doing something like this?
>>>>>
>>>>> List<?> values =
>>>>> (List<?>)eObject.eContainer().eGet(eObject.eContainmentFeature());
>>>>> int index = values.indexOf(eObject);
>>>>>
>>>>> And then incrementing or decrementing index and checking it abounds
>>>>> the 0 or value.size()?
>>>>>
>>>>>
>>>>> Philipp W. Kutter wrote:
>>>>>> Hi, Everybody.
>>>>>> I tried several ways to derive position, predecessor, and
>>>>>> successor of
>>>>>> lists in earlier projects.
>>>>>>
>>>>>> What is the best way doing this?
>>>>>>
>>>>>> I remember starting with the EObject, finding its containing
>>>>>> feature, geting the EList like this, and then looking it through.
>>>>>>
>>>>>>
>>>>>> Is there a faster, easier way?
>>>>>>
>>>>>> Best, Philipp
>>>>>
Previous Topic:Declare an array type
Next Topic:How to deserialize an xml string into an EObject
Goto Forum:
  


Current Time: Fri Apr 26 07:57:09 GMT 2024

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

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

Back to the top