Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » EMF many-valued features, set or sequence?
EMF many-valued features, set or sequence? [message #50539] Mon, 11 February 2008 07:27 Go to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
Hi.
Up to now I thought EMF features would always result to be sequences,
and I had to write code like

structure
->iterate( ou : OrganizationalUnit;
a : Sequence(OrganizationalUnit) = Sequence{}
| let start: Sequence(OrganizationalUnit)
= a->append(ou) in
ou.allSubUnits()
->iterate(subOu: OrganizationalUnit;
subA: Sequence(OrganizationalUnit) = start
| subA->append(subOu)
)
)

all the time. Union or concatenate would be practical...


Then I started to use the "closure" feature of MDT OCL, but when i try

self->closure(directSubRoles)->append(self)

I get an error:
Cannot find operation (append(ContractRole)) for the type
(Set(ContractRole))


Thus here, I end up with a set..


Is there an advice in how to put the members of two ECore features
together? Is there something like "appendAll()"?

Is there a way to make a set from a sequence?

Yes, and before I forget it. Given a many-valued feature F of type T,
when I try:

let f2: Sequence(T) = F in f2

then I get an error. What is the correct OCL type for a a many-valued
feature F of type T?

Best, Philipp
Re: EMF many-valued features, set or sequence? [message #50569 is a reply to message #50539] Mon, 11 February 2008 15:17 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Philipp,

See some replies in-line, below.

HTH,

Christian


Philipp W. Kutter wrote:

> Hi.
> Up to now I thought EMF features would always result to be sequences,
> and I had to write code like
>
> structure
> ->iterate( ou : OrganizationalUnit;
> a : Sequence(OrganizationalUnit) = Sequence{}
> | let start: Sequence(OrganizationalUnit)
> = a->append(ou) in
> ou.allSubUnits()
> ->iterate(subOu: OrganizationalUnit;
> subA: Sequence(OrganizationalUnit) = start
> | subA->append(subOu)
> )
> )
>
> all the time. Union or concatenate would be practical...

Ouch! How about this:

structure->asSet()->union(structure.allSubUnits()->asSet())

This gathers up the OUs in 'structure' together with all of their subunits.
Or, rather, I think it should :-)


> Then I started to use the "closure" feature of MDT OCL, but when i try
>
> self->closure(directSubRoles)->append(self)
>
> I get an error:
> Cannot find operation (append(ContractRole)) for the type
> (Set(ContractRole))

Right. Sets aren't ordered, so you would do

self->closure(directSubRoles)->including(self)


> Thus here, I end up with a set..
>
>
> Is there an advice in how to put the members of two ECore features
> together? Is there something like "appendAll()"?

All Collection types in OCL have a union() operation that constructs a new
collection containing all of the elements of the source collection and all
of the elements of the argument collection (which must be of the same
kind).


> Is there a way to make a set from a sequence?

Yes. Any kind of collection can be converted to any other kind using the
asSet(), asSequence(), asOrderedSet(), and asBag() operations.


> Yes, and before I forget it. Given a many-valued feature F of type T,
> when I try:
>
> let f2: Sequence(T) = F in f2
>
> then I get an error. What is the correct OCL type for a a many-valued
> feature F of type T?

It depends on the uniqueness and orderedness of the feature:

isUnique isOrdered Collection Type
======== ========= ===============
false false Bag
false true Sequence
true false Set
true true OrderedSet


> Best, Philipp
Previous Topic:help me with a constraint please :)
Next Topic:[Announce] MDT OCL 1.2.0M5 is available
Goto Forum:
  


Current Time: Fri Apr 26 07:17:57 GMT 2024

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

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

Back to the top