Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Collection beginner question
Collection beginner question [message #71034] Thu, 28 May 2009 13:22 Go to next message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Hey all,

the types OrderedSet and Sequence are orderede types. But which kind of
ordering relation is defined on them? And how to define such a relation?

Thanks
Timothy
Re: Collection beginner question [message #71056 is a reply to message #71034] Thu, 28 May 2009 18:39 Go to previous messageGo to next message
Adolfo Sanchez-Barbudo Herrera is currently offline Adolfo Sanchez-Barbudo Herrera
Messages: 253
Registered: July 2009
Senior Member
Hi Tomothy,

I'm not sure what you mean "kind of ordering relation". They are
different (not-related) types after all. You may use specific operations
(defined in the standard library) to obtain an OrderedSet from a
Sequence, and viceversa.

The difference between these types basically is that in a Sequence you
can have different occurrences of the same object, which is not valid in
an OrderedSet. For example, look at the following valid expression

Sequence {1, 1 , 2, 3}->asOrderedSet() = OrderedSet {1, 2, 3}

They are both ordered collections (you could access the object in the
first position of the collection), but you can't have multiple
occurrences of the same object (the integer '1', in this case) in the
OrderedSet.

Cheers,
Adolfo.


Timothy Marc escribió:
> Hey all,
>
> the types OrderedSet and Sequence are orderede types. But which kind of
> ordering relation is defined on them? And how to define such a relation?
>
> Thanks
> Timothy
Re: Collection beginner question [message #71076 is a reply to message #71056] Thu, 28 May 2009 19:04 Go to previous messageGo to next message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Okay,

let me precise my question. For example:

context Class:op(arr:OrderedSet(Class2))

The parameter in the uml model is specified as

Parameter arr (in), ordered, unique, upperBound *

But, where can i define the kind of the ordering??? For me, it looks
like this is more or less an information, which is only relevant for the
code generation.

hope, my question is now more clear?


thx
timothy

Adolfo Sánchez-Barbudo Herrera schrieb:
> Hi Tomothy,
>
> I'm not sure what you mean "kind of ordering relation". They are
> different (not-related) types after all. You may use specific operations
> (defined in the standard library) to obtain an OrderedSet from a
> Sequence, and viceversa.
>
> The difference between these types basically is that in a Sequence you
> can have different occurrences of the same object, which is not valid in
> an OrderedSet. For example, look at the following valid expression
>
> Sequence {1, 1 , 2, 3}->asOrderedSet() = OrderedSet {1, 2, 3}
>
> They are both ordered collections (you could access the object in the
> first position of the collection), but you can't have multiple
> occurrences of the same object (the integer '1', in this case) in the
> OrderedSet.
>
> Cheers,
> Adolfo.
>
>
> Timothy Marc escribió:
>> Hey all,
>>
>> the types OrderedSet and Sequence are orderede types. But which kind
>> of ordering relation is defined on them? And how to define such a
>> relation?
>>
>> Thanks
>> Timothy
Re: Collection beginner question [message #71095 is a reply to message #71076] Thu, 28 May 2009 20:23 Go to previous messageGo to next message
Adolfo Sanchez-Barbudo Herrera is currently offline Adolfo Sanchez-Barbudo Herrera
Messages: 253
Registered: July 2009
Senior Member
Hi Timothy,

Look at the following table. I guess it could help you...

Collection Ordered Unique
--------------------------------
Set false true
OrderedSet true true
Sequence true false
Bag false false


The unique qualifier is the key in your case to distinguish between
OrderedSet and Sequence.

As I said, the OrderedSet doesn't allow multiple occurrences in the
collection, which is modelled in your case with unique=true.

Cheers,
Adolfo.


Timothy Marc escribió:
> Okay,
>
> let me precise my question. For example:
>
> context Class:op(arr:OrderedSet(Class2))
>
> The parameter in the uml model is specified as
>
> Parameter arr (in), ordered, unique, upperBound *
>
> But, where can i define the kind of the ordering??? For me, it looks
> like this is more or less an information, which is only relevant for the
> code generation.
>
> hope, my question is now more clear?
>
>
> thx
> timothy
>
> Adolfo Sánchez-Barbudo Herrera schrieb:
>> Hi Tomothy,
>>
>> I'm not sure what you mean "kind of ordering relation". They are
>> different (not-related) types after all. You may use specific
>> operations (defined in the standard library) to obtain an OrderedSet
>> from a Sequence, and viceversa.
>>
>> The difference between these types basically is that in a Sequence you
>> can have different occurrences of the same object, which is not valid
>> in an OrderedSet. For example, look at the following valid expression
>>
>> Sequence {1, 1 , 2, 3}->asOrderedSet() = OrderedSet {1, 2, 3}
>>
>> They are both ordered collections (you could access the object in the
>> first position of the collection), but you can't have multiple
>> occurrences of the same object (the integer '1', in this case) in the
>> OrderedSet.
>>
>> Cheers,
>> Adolfo.
>>
>>
>> Timothy Marc escribió:
>>> Hey all,
>>>
>>> the types OrderedSet and Sequence are orderede types. But which kind
>>> of ordering relation is defined on them? And how to define such a
>>> relation?
>>>
>>> Thanks
>>> Timothy
Re: Collection beginner question [message #71115 is a reply to message #71095] Fri, 29 May 2009 09:21 Go to previous messageGo to next message
Eclipse User
Originally posted by: Alexander.Igdalov.borland.com

Hi Timothy and Adolfo,

I suppose Timothy wants to find out by which relation are the elements
ordered. IOW, where the comparator is=))

Elements in OrderedSet and Sequence are ordered by the initial order
(sorry for tautology) in which they were put in the collection. Since
OCL collections are immutable their order is set on collection
instantiation. It means that:
Sequence {80, 2, 100, 55} would be an (ordered) sequence in which the
first element is 80, the second is 2 and so forth. Elements themselves
are not compared.

If you want to change the order of the elements in a collection you need
to create another re-ordered collection with the same elements. In some
cases for sorting in ascending order you can use sortedBy() operation.
For instance,

eClasses->sortedBy(name) -- given that eClasses in a collection of EClass'es

Note, that in this case the elements must be comparable. In terms of UML
the type of the body expression must have the < operation defined. The <
operation must return a Boolean value and must be transitive (i.e., if a
< b and b < c then a < c). This is true for collections of primitive
types, for instance.

HTH,
Alex.

Adolfo Sánchez-Barbudo Herrera wrote:
> Hi Timothy,
>
> Look at the following table. I guess it could help you...
>
> Collection Ordered Unique
> --------------------------------
> Set false true
> OrderedSet true true
> Sequence true false
> Bag false false
>
>
> The unique qualifier is the key in your case to distinguish between
> OrderedSet and Sequence.
>
> As I said, the OrderedSet doesn't allow multiple occurrences in the
> collection, which is modelled in your case with unique=true.
>
> Cheers,
> Adolfo.
>
>
> Timothy Marc escribió:
>> Okay,
>>
>> let me precise my question. For example:
>>
>> context Class:op(arr:OrderedSet(Class2))
>>
>> The parameter in the uml model is specified as
>>
>> Parameter arr (in), ordered, unique, upperBound *
>>
>> But, where can i define the kind of the ordering??? For me, it looks
>> like this is more or less an information, which is only relevant for
>> the code generation.
>>
>> hope, my question is now more clear?
>>
>>
>> thx
>> timothy
>>
>> Adolfo Sánchez-Barbudo Herrera schrieb:
>>> Hi Tomothy,
>>>
>>> I'm not sure what you mean "kind of ordering relation". They are
>>> different (not-related) types after all. You may use specific
>>> operations (defined in the standard library) to obtain an OrderedSet
>>> from a Sequence, and viceversa.
>>>
>>> The difference between these types basically is that in a Sequence
>>> you can have different occurrences of the same object, which is not
>>> valid in an OrderedSet. For example, look at the following valid
>>> expression
>>>
>>> Sequence {1, 1 , 2, 3}->asOrderedSet() = OrderedSet {1, 2, 3}
>>>
>>> They are both ordered collections (you could access the object in the
>>> first position of the collection), but you can't have multiple
>>> occurrences of the same object (the integer '1', in this case) in the
>>> OrderedSet.
>>>
>>> Cheers,
>>> Adolfo.
>>>
>>>
>>> Timothy Marc escribió:
>>>> Hey all,
>>>>
>>>> the types OrderedSet and Sequence are orderede types. But which kind
>>>> of ordering relation is defined on them? And how to define such a
>>>> relation?
>>>>
>>>> Thanks
>>>> Timothy
Re: Collection beginner question [message #71135 is a reply to message #71115] Fri, 29 May 2009 10:40 Go to previous messageGo to next message
Adolfo Sanchez-Barbudo Herrera is currently offline Adolfo Sanchez-Barbudo Herrera
Messages: 253
Registered: July 2009
Senior Member
Ouch,

I've realized that

1. the example which I chose, may have confused the reader instead of
helping ;P
2. I didn't obviously catch the question.

As I explained and alex remarked, the term "ordered" just indicates that
the elements have "an order or position" in the collection, and
therefore you can access the elements by its position in it (you could
use the "at" operator).

I agree with the whole explanation of Alex. Thank you for catching the
problem and for explaining it;)

Cheers,
Adolfo.

Alexander Igdalov escribió:
> Hi Timothy and Adolfo,
>
> I suppose Timothy wants to find out by which relation are the elements
> ordered. IOW, where the comparator is=))
>
> Elements in OrderedSet and Sequence are ordered by the initial order
> (sorry for tautology) in which they were put in the collection. Since
> OCL collections are immutable their order is set on collection
> instantiation. It means that:
> Sequence {80, 2, 100, 55} would be an (ordered) sequence in which the
> first element is 80, the second is 2 and so forth. Elements themselves
> are not compared.
>
> If you want to change the order of the elements in a collection you need
> to create another re-ordered collection with the same elements. In some
> cases for sorting in ascending order you can use sortedBy() operation.
> For instance,
>
> eClasses->sortedBy(name) -- given that eClasses in a collection of
> EClass'es
>
> Note, that in this case the elements must be comparable. In terms of UML
> the type of the body expression must have the < operation defined. The <
> operation must return a Boolean value and must be transitive (i.e., if a
> < b and b < c then a < c). This is true for collections of primitive
> types, for instance.
>
> HTH,
> Alex.
>
> Adolfo Sánchez-Barbudo Herrera wrote:
>> Hi Timothy,
>>
>> Look at the following table. I guess it could help you...
>>
>> Collection Ordered Unique
>> --------------------------------
>> Set false true
>> OrderedSet true true
>> Sequence true false
>> Bag false false
>>
>>
>> The unique qualifier is the key in your case to distinguish between
>> OrderedSet and Sequence.
>>
>> As I said, the OrderedSet doesn't allow multiple occurrences in the
>> collection, which is modelled in your case with unique=true.
>>
>> Cheers,
>> Adolfo.
>>
>>
>> Timothy Marc escribió:
>>> Okay,
>>>
>>> let me precise my question. For example:
>>>
>>> context Class:op(arr:OrderedSet(Class2))
>>>
>>> The parameter in the uml model is specified as
>>>
>>> Parameter arr (in), ordered, unique, upperBound *
>>>
>>> But, where can i define the kind of the ordering??? For me, it looks
>>> like this is more or less an information, which is only relevant for
>>> the code generation.
>>>
>>> hope, my question is now more clear?
>>>
>>>
>>> thx
>>> timothy
>>>
>>> Adolfo Sánchez-Barbudo Herrera schrieb:
>>>> Hi Tomothy,
>>>>
>>>> I'm not sure what you mean "kind of ordering relation". They are
>>>> different (not-related) types after all. You may use specific
>>>> operations (defined in the standard library) to obtain an OrderedSet
>>>> from a Sequence, and viceversa.
>>>>
>>>> The difference between these types basically is that in a Sequence
>>>> you can have different occurrences of the same object, which is not
>>>> valid in an OrderedSet. For example, look at the following valid
>>>> expression
>>>>
>>>> Sequence {1, 1 , 2, 3}->asOrderedSet() = OrderedSet {1, 2, 3}
>>>>
>>>> They are both ordered collections (you could access the object in
>>>> the first position of the collection), but you can't have multiple
>>>> occurrences of the same object (the integer '1', in this case) in
>>>> the OrderedSet.
>>>>
>>>> Cheers,
>>>> Adolfo.
>>>>
>>>>
>>>> Timothy Marc escribió:
>>>>> Hey all,
>>>>>
>>>>> the types OrderedSet and Sequence are orderede types. But which
>>>>> kind of ordering relation is defined on them? And how to define
>>>>> such a relation?
>>>>>
>>>>> Thanks
>>>>> Timothy
Re: Collection beginner question [message #71155 is a reply to message #71135] Fri, 29 May 2009 12:56 Go to previous messageGo to next message
Eclipse User
Originally posted by: Alexander.Igdalov.borland.com

Adolfo Sánchez-Barbudo Herrera wrote:
> Ouch,
>
> I've realized that
>
> 1. the example which I chose, may have confused the reader instead of
> helping ;P
> 2. I didn't obviously catch the question.
>
> As I explained and alex remarked, the term "ordered" just indicates that
> the elements have "an order or position" in the collection, and
> therefore you can access the elements by its position in it (you could
> use the "at" operator).
>
> I agree with the whole explanation of Alex. Thank you for catching the
> problem and for explaining it;)
>

NP:) Let's see whether it was what Timothy wanted.

> Cheers,
> Adolfo.
>
> Alexander Igdalov escribió:
>> Hi Timothy and Adolfo,
>>
>> I suppose Timothy wants to find out by which relation are the elements
>> ordered. IOW, where the comparator is=))
>>
>> Elements in OrderedSet and Sequence are ordered by the initial order
>> (sorry for tautology) in which they were put in the collection. Since
>> OCL collections are immutable their order is set on collection
>> instantiation. It means that:
>> Sequence {80, 2, 100, 55} would be an (ordered) sequence in which the
>> first element is 80, the second is 2 and so forth. Elements
>> themselves are not compared.
>>
>> If you want to change the order of the elements in a collection you
>> need to create another re-ordered collection with the same elements.
>> In some cases for sorting in ascending order you can use sortedBy()
>> operation. For instance,
>>
>> eClasses->sortedBy(name) -- given that eClasses in a collection of
>> EClass'es
>>
>> Note, that in this case the elements must be comparable. In terms of
>> UML the type of the body expression must have the < operation defined.
>> The < operation must return a Boolean value and must be transitive
>> (i.e., if a < b and b < c then a < c). This is true for collections of
>> primitive types, for instance.
>>
>> HTH,
>> Alex.
>>
>> Adolfo Sánchez-Barbudo Herrera wrote:
>>> Hi Timothy,
>>>
>>> Look at the following table. I guess it could help you...
>>>
>>> Collection Ordered Unique
>>> --------------------------------
>>> Set false true
>>> OrderedSet true true
>>> Sequence true false
>>> Bag false false
>>>
>>>
>>> The unique qualifier is the key in your case to distinguish between
>>> OrderedSet and Sequence.
>>>
>>> As I said, the OrderedSet doesn't allow multiple occurrences in the
>>> collection, which is modelled in your case with unique=true.
>>>
>>> Cheers,
>>> Adolfo.
>>>
>>>
>>> Timothy Marc escribió:
>>>> Okay,
>>>>
>>>> let me precise my question. For example:
>>>>
>>>> context Class:op(arr:OrderedSet(Class2))
>>>>
>>>> The parameter in the uml model is specified as
>>>>
>>>> Parameter arr (in), ordered, unique, upperBound *
>>>>
>>>> But, where can i define the kind of the ordering??? For me, it looks
>>>> like this is more or less an information, which is only relevant for
>>>> the code generation.
>>>>
>>>> hope, my question is now more clear?
>>>>
>>>>
>>>> thx
>>>> timothy
>>>>
>>>> Adolfo Sánchez-Barbudo Herrera schrieb:
>>>>> Hi Tomothy,
>>>>>
>>>>> I'm not sure what you mean "kind of ordering relation". They are
>>>>> different (not-related) types after all. You may use specific
>>>>> operations (defined in the standard library) to obtain an
>>>>> OrderedSet from a Sequence, and viceversa.
>>>>>
>>>>> The difference between these types basically is that in a Sequence
>>>>> you can have different occurrences of the same object, which is not
>>>>> valid in an OrderedSet. For example, look at the following valid
>>>>> expression
>>>>>
>>>>> Sequence {1, 1 , 2, 3}->asOrderedSet() = OrderedSet {1, 2, 3}
>>>>>
>>>>> They are both ordered collections (you could access the object in
>>>>> the first position of the collection), but you can't have multiple
>>>>> occurrences of the same object (the integer '1', in this case) in
>>>>> the OrderedSet.
>>>>>
>>>>> Cheers,
>>>>> Adolfo.
>>>>>
>>>>>
>>>>> Timothy Marc escribió:
>>>>>> Hey all,
>>>>>>
>>>>>> the types OrderedSet and Sequence are orderede types. But which
>>>>>> kind of ordering relation is defined on them? And how to define
>>>>>> such a relation?
>>>>>>
>>>>>> Thanks
>>>>>> Timothy
Re: Collection beginner question [message #71194 is a reply to message #71155] Tue, 02 June 2009 20:36 Go to previous message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Alex,

yes, this was exactly the kind of hint, i was looking for :-) Thanks a
lot for that explanation.
And also, thanks to you Adolfo :-)

Regards Timothy

Alexander Igdalov schrieb:
> Adolfo Sánchez-Barbudo Herrera wrote:
>> Ouch,
>>
>> I've realized that
>>
>> 1. the example which I chose, may have confused the reader instead of
>> helping ;P
>> 2. I didn't obviously catch the question.
>>
>> As I explained and alex remarked, the term "ordered" just indicates
>> that the elements have "an order or position" in the collection, and
>> therefore you can access the elements by its position in it (you could
>> use the "at" operator).
>>
>> I agree with the whole explanation of Alex. Thank you for catching the
>> problem and for explaining it;)
>>
>
> NP:) Let's see whether it was what Timothy wanted.
>
>> Cheers,
>> Adolfo.
>>
>> Alexander Igdalov escribió:
>>> Hi Timothy and Adolfo,
>>>
>>> I suppose Timothy wants to find out by which relation are the
>>> elements ordered. IOW, where the comparator is=))
>>>
>>> Elements in OrderedSet and Sequence are ordered by the initial order
>>> (sorry for tautology) in which they were put in the collection. Since
>>> OCL collections are immutable their order is set on collection
>>> instantiation. It means that:
>>> Sequence {80, 2, 100, 55} would be an (ordered) sequence in which the
>>> first element is 80, the second is 2 and so forth. Elements
>>> themselves are not compared.
>>>
>>> If you want to change the order of the elements in a collection you
>>> need to create another re-ordered collection with the same elements.
>>> In some cases for sorting in ascending order you can use sortedBy()
>>> operation. For instance,
>>>
>>> eClasses->sortedBy(name) -- given that eClasses in a collection of
>>> EClass'es
>>>
>>> Note, that in this case the elements must be comparable. In terms of
>>> UML the type of the body expression must have the < operation
>>> defined. The < operation must return a Boolean value and must be
>>> transitive (i.e., if a < b and b < c then a < c). This is true for
>>> collections of primitive types, for instance.
>>>
>>> HTH,
>>> Alex.
>>>
>>> Adolfo Sánchez-Barbudo Herrera wrote:
>>>> Hi Timothy,
>>>>
>>>> Look at the following table. I guess it could help you...
>>>>
>>>> Collection Ordered Unique
>>>> --------------------------------
>>>> Set false true
>>>> OrderedSet true true
>>>> Sequence true false
>>>> Bag false false
>>>>
>>>>
>>>> The unique qualifier is the key in your case to distinguish between
>>>> OrderedSet and Sequence.
>>>>
>>>> As I said, the OrderedSet doesn't allow multiple occurrences in the
>>>> collection, which is modelled in your case with unique=true.
>>>>
>>>> Cheers,
>>>> Adolfo.
>>>>
>>>>
>>>> Timothy Marc escribió:
>>>>> Okay,
>>>>>
>>>>> let me precise my question. For example:
>>>>>
>>>>> context Class:op(arr:OrderedSet(Class2))
>>>>>
>>>>> The parameter in the uml model is specified as
>>>>>
>>>>> Parameter arr (in), ordered, unique, upperBound *
>>>>>
>>>>> But, where can i define the kind of the ordering??? For me, it
>>>>> looks like this is more or less an information, which is only
>>>>> relevant for the code generation.
>>>>>
>>>>> hope, my question is now more clear?
>>>>>
>>>>>
>>>>> thx
>>>>> timothy
>>>>>
>>>>> Adolfo Sánchez-Barbudo Herrera schrieb:
>>>>>> Hi Tomothy,
>>>>>>
>>>>>> I'm not sure what you mean "kind of ordering relation". They are
>>>>>> different (not-related) types after all. You may use specific
>>>>>> operations (defined in the standard library) to obtain an
>>>>>> OrderedSet from a Sequence, and viceversa.
>>>>>>
>>>>>> The difference between these types basically is that in a Sequence
>>>>>> you can have different occurrences of the same object, which is
>>>>>> not valid in an OrderedSet. For example, look at the following
>>>>>> valid expression
>>>>>>
>>>>>> Sequence {1, 1 , 2, 3}->asOrderedSet() = OrderedSet {1, 2, 3}
>>>>>>
>>>>>> They are both ordered collections (you could access the object in
>>>>>> the first position of the collection), but you can't have multiple
>>>>>> occurrences of the same object (the integer '1', in this case) in
>>>>>> the OrderedSet.
>>>>>>
>>>>>> Cheers,
>>>>>> Adolfo.
>>>>>>
>>>>>>
>>>>>> Timothy Marc escribió:
>>>>>>> Hey all,
>>>>>>>
>>>>>>> the types OrderedSet and Sequence are orderede types. But which
>>>>>>> kind of ordering relation is defined on them? And how to define
>>>>>>> such a relation?
>>>>>>>
>>>>>>> Thanks
>>>>>>> Timothy
Previous Topic:[Announce] MDT OCL 1.3.0RC3 is available
Next Topic:OCL for sequence diagram
Goto Forum:
  


Current Time: Wed Sep 17 11:33:17 GMT 2014

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

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