Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Re: ocl constraint on an enumeration
Re: ocl constraint on an enumeration [message #25196] Tue, 29 May 2007 13:27 Go to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Tex,

It's best to ask about OCL on the OCL newsgroup, which I've added to the
"to" list in my reply. I'm not sure if there is a way to get the
numeric value of an enum constant, but Christian will see your question
on the other newsgroup and will know if that's possible.


Tex Twil wrote:
> Hello,
> I have the following enumeration table "LEVEL":
> Zero = 0
> One = 1
> Two = 2
>
> I also have some tables with this enumeration attribute. Something like :
> A.level : LEVEL
> B.level : LEVEL
>
> I'd like to compare the value of the LEVEL value in a OCL constraint:
>
> .. a.level <= b.level ...
>
> But this doesn't work because the enumeration fields can't be
> compared. What could be the solution for this problem.
>
> Thanks.
>
>
Re: ocl constraint on an enumeration [message #25277 is a reply to message #25196] Tue, 29 May 2007 13:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Tex,

UML/EMOF/OCL do not have a notion of comparison of enumeration literals.
They are pretty much just labels.

You will need to implement an external mapping of LEVELs to Integers,
something like:

package whateverPackage
context LEVEL
def: levelMapping : Set(Tuple(level : LEVEL, value : Integer)) =
Set{Tuple{LEVEL::Zero, 0},
Tuple{LEVEL::One, 1},
Tuple{LEVEL::Two, 2}}
def: lessThan(other : LEVEL) : Boolean =
levelMapping->any(level = self).value
< levelMapping->any(level = other).value
endpackage

Then, you can use the lessThan operation in any constraint, e.g.,

package whateverPackage
context A::foo(b : B)
pre: self.level.lessThan(b.level)
endpackage

HTH,

Christian

Ed Merks wrote:

> Tex,
>
> It's best to ask about OCL on the OCL newsgroup, which I've added to the
> "to" list in my reply. I'm not sure if there is a way to get the
> numeric value of an enum constant, but Christian will see your question
> on the other newsgroup and will know if that's possible.
>
>
> Tex Twil wrote:
>> Hello,
>> I have the following enumeration table "LEVEL":
>> Zero = 0
>> One = 1
>> Two = 2
>>
>> I also have some tables with this enumeration attribute. Something like :
>> A.level : LEVEL
>> B.level : LEVEL
>>
>> I'd like to compare the value of the LEVEL value in a OCL constraint:
>>
>> .. a.level <= b.level ...
>>
>> But this doesn't work because the enumeration fields can't be
>> compared. What could be the solution for this problem.
>>
>> Thanks.
>>
>>
Re: ocl constraint on an enumeration [message #25357 is a reply to message #25196] Tue, 29 May 2007 14:03 Go to previous message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
ok thank you !
Previous Topic:general ocl question
Next Topic:Navigating from Interface to typed ports.
Goto Forum:
  


Current Time: Thu Apr 25 04:22:26 GMT 2024

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

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

Back to the top