Re: ocl constraint on an enumeration [message #25196] |
Tue, 29 May 2007 13:27 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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.
>>
>>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03082 seconds