Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » LiteralUnlimitedNatural why int(why is LiteralUnlimitedNatural a int and not a long)
LiteralUnlimitedNatural why int [message #1322265] Tue, 29 April 2014 19:30 Go to next message
Pieter Martin is currently offline Pieter MartinFriend
Messages: 14
Registered: July 2013
Junior Member
Hi,

I just recently realized that a LiteralUnlimitedNatural is a int. I expected it to be a long.

Is there a reason why it is not a java long?

Thanks
Pieter
Re: LiteralUnlimitedNatural why int [message #1322317 is a reply to message #1322265] Tue, 29 April 2014 20:08 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 930
Registered: July 2009
Senior Member
Hi, Pieter,

The only meaningful differences between UML's UnlimitedNatural and
Integer types are:

* UnlimitedNatural's range does not include zero and negative numbers
(like the
natural numbers of mathematics)
* UnlimitedNatural includes the special ' * ' value indicating an
unlimited upper multiplicity
bound (which does not correspond to any number in the mathematical
natural domain)

As UnlimitedNatural has no negative space, it is convenient to
represent ' * ' with -1 in Java.

Apart from that, long hasn't sufficient precision to represent the
entire natural domain, and BigInteger is unwieldy for such common usage
as multiplicity, so int is the most practical Java-ish representation.

Note that, in practice, it is probably quite rare to see any other
multiplicity upper bounds than 1, 2, or * .

HTH,

Christian


On 2014-04-29 19:30:53 +0000, Pieter Martin said:

> Hi,
>
> I just recently realized that a LiteralUnlimitedNatural is a int. I
> expected it to be a long.
>
> Is there a reason why it is not a java long?
>
> Thanks
> Pieter
Re: LiteralUnlimitedNatural why int [message #1322332 is a reply to message #1322317] Tue, 29 April 2014 20:19 Go to previous messageGo to next message
Pieter Martin is currently offline Pieter MartinFriend
Messages: 14
Registered: July 2013
Junior Member
Thanks,

I'll import the Java Primitive Types then as I need to support longs.

Regards
Pieter
Re: LiteralUnlimitedNatural why int [message #1322355 is a reply to message #1322317] Tue, 29 April 2014 20:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4315
Registered: July 2009
Senior Member
Hi

Correction: An UnlimitedNatural may have the value zero.

[In EMF, the value -2 is also used for some undecided XSD status.]

However since UnlimitedNatural is only used to describe the upper bound
of a multiplicity, a zero value can never be used in a useful model.

Note that UnlimitedNatural is not a number, despite my misguided
rationalization in OCL 2.3 that will hopefully be reverted in OCL 2.5.

UnlimitedNatural has a value '*' that is unrepresentable as either
Integer or Real, therefore UnlimitedNatural does not conform to Integer
or Real and should not be freely convertible to Integer or Real. Expect
UnlimitedNatral to become increasingly unusable without explicit
conversions.

You are better off thinking of UnlimitedNatural as an Enumeration with a
very large number of enumerated values.

Integer and UnlimitedNatural are unbounded so neither int nor long is
adequate. Some tools impose limitations that work nearly always but the
occasional consumer complains. Eclipse OCL has grown from int to long;
the Pivot OCL uses Number and so supports the most convenient
polymorphic representation.

Regards

Ed Willink

On 29/04/2014 21:08, Christian W. Damus wrote:
> Hi, Pieter,
>
> The only meaningful differences between UML's UnlimitedNatural and
> Integer types are:
>
> * UnlimitedNatural's range does not include zero and negative numbers
> (like the
> natural numbers of mathematics)
> * UnlimitedNatural includes the special ' * ' value indicating an
> unlimited upper multiplicity
> bound (which does not correspond to any number in the mathematical
> natural domain)
>
> As UnlimitedNatural has no negative space, it is convenient to
> represent ' * ' with -1 in Java.
>
> Apart from that, long hasn't sufficient precision to represent the
> entire natural domain, and BigInteger is unwieldy for such common
> usage as multiplicity, so int is the most practical Java-ish
> representation.
>
> Note that, in practice, it is probably quite rare to see any other
> multiplicity upper bounds than 1, 2, or * .
>
> HTH,
>
> Christian
>
>
> On 2014-04-29 19:30:53 +0000, Pieter Martin said:
>
>> Hi,
>>
>> I just recently realized that a LiteralUnlimitedNatural is a int. I
>> expected it to be a long.
>>
>> Is there a reason why it is not a java long?
>>
>> Thanks
>> Pieter
>
>
Re: LiteralUnlimitedNatural why int [message #1323201 is a reply to message #1322355] Wed, 30 April 2014 06:20 Go to previous messageGo to next message
Pieter Martin is currently offline Pieter MartinFriend
Messages: 14
Registered: July 2013
Junior Member
Hi,

I am afraid you left me somewhat confused?

Quote:
However since UnlimitedNatural is only used to describe the upper bound
of a multiplicity, a zero value can never be used in a useful model.


Quote:
Note that UnlimitedNatural is not a number


For a standard property of type Primitive::UnlimitedNatural with upper limit of 1 it may have any value (number) between 0 and * which in UML2 java is bounded by int's upper limit.

This is/was my understanding. Am I missing something or are we talking about UnlimitedNatural at different meta model levels?

Thanks
Pieter
Re: LiteralUnlimitedNatural why int [message #1323363 is a reply to message #1323201] Wed, 30 April 2014 08:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4315
Registered: July 2009
Senior Member
Hi

Yes a Property upperbound can be an value between 0 and *.

But UnlimitedNatural is not a number; it just looks like one. Since it
is not a number an implementation may choose any representation it likes
and "int" is a convenient choice where 31 bits is sufficient. There is
spare representational capacity for the irregular "*" value.

You should not be able to add two upperbound values without first
converting their values to Integer, which is a number. And once the OCL
specification is clarified you will not be able to use
..oclAsType(UnlimitedNatural) to cast the integer result; a new operation
will be needed. Perhaps

(bound1.asInteger() + bound2.asInteger()).asUnlimitedNatural() --
asInteger/asUnlimitedNatural give invalid for bad values

Just the same as in Java you cannot write for a Weekday enumeration

weekday3 = weekday1 + weekday2;

you must write something horrible like (not checked, but you should get
the idea)

weekday3 = Weekday.valueOf((weekday1.ordinal() + weekday2.ordinal()) % 7);

Regards

Ed Willink

On 30/04/2014 07:20, Pieter Martin wrote:
> Hi,
>
> I am afraid you left me somewhat confused?
>
> Quote:
>> However since UnlimitedNatural is only used to describe the upper bound
>> of a multiplicity, a zero value can never be used in a useful model.
>
>
> Quote:
>> Note that UnlimitedNatural is not a number
>
>
> For a standard property of type Primitive::UnlimitedNatural with upper
> limit of 1 it may have any value (number) between 0 and * which in
> UML2 java is bounded by int's upper limit.
>
> This is/was my understanding. Am I missing something or are we talking
> about UnlimitedNatural at different meta model levels?
>
> Thanks
> Pieter
Re: LiteralUnlimitedNatural why int [message #1324058 is a reply to message #1323363] Wed, 30 April 2014 15:38 Go to previous message
Pieter Martin is currently offline Pieter MartinFriend
Messages: 14
Registered: July 2013
Junior Member
Ok thanks,

Regards
Pieter
Previous Topic:Check if given Stereotype can be applied
Next Topic:UML-specific Diagnostician?
Goto Forum:
  


Current Time: Sun Apr 26 03:04:43 GMT 2015

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

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