Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL Enumeration ordered?
OCL Enumeration ordered? [message #553661] Wed, 18 August 2010 12:03 Go to next message
Joern is currently offline JoernFriend
Messages: 22
Registered: March 2010
Junior Member
Playing around with the enumerations in OCL I am wondering, whether an enumeration is ordered in OCL and how to access the ordinal number of an element.

If I retrieve for example the instances of an enumeration in the OCL Interactive Console by
EnumType.allInstances()

I get something like
Element1 = 0
Element2 = 1
Element3 = 2

But I see no possibility to access the ordinal ("0", "1" etc.).
Any ideas?

[Updated on: Wed, 18 August 2010 12:03]

Report message to a moderator

Re: OCL Enumeration ordered? [message #553740 is a reply to message #553661] Wed, 18 August 2010 16:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Joern

EnumType.allInstances()->asSequence()->indexOf(...) will give you a
1-based integer.

But since allInstances() returns a Set, you will be at the mercy of the
implmentation. Ordering will only be sensible if the implementation
happens to use a LinkedHashSet or List.

However UML defines Enumeration::ownedLiteral as ordered, so I'll raise
an OMG OCL issue to get Enumeration.allInstances changed to return an
OrderedSet.

Regards

Ed Willink



On 18/08/2010 13:03, Joern wrote:
> Playing around with the enumerations in OCL I am wondering, whether an
> enumeration is ordered in OCL and how to access the ordinal number of an
> element.
>
> If I retrieve for example the instances of an enumeration in the OCL
> Interactive Console by EnumType.allInstances() I get something like
> Element1 = 0
> Element2 =1
> Element3=2
> But I see no possibility to access the ordinal ("0", "1" etc.).
> Any ideas?
Re: OCL Enumeration ordered? [message #553750 is a reply to message #553740] Wed, 18 August 2010 17:11 Go to previous message
Joern is currently offline JoernFriend
Messages: 22
Registered: March 2010
Junior Member
Hi Ed,

thanks for your quick reply.

> EnumType.allInstances()->asSequence()->indexOf(...)

Does not work for me (at least the OCL Interpreter Console does not compute). I will post a bug.

Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=323069

> But since allInstances() returns a Set, you will be at the mercy of the
> implmentation. Ordering will only be sensible if the implementation

Therefore I will have to switch to define explicit ordinals.

Thank you again,

Joern

[Updated on: Wed, 18 August 2010 17:26]

Report message to a moderator

Previous Topic:[OCLInEcore] Operator ^
Next Topic:OCLinEcore issues with derived attributes/operations
Goto Forum:
  


Current Time: Thu Apr 18 19:36:30 GMT 2024

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

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

Back to the top