EMF many-valued features, set or sequence? [message #50539] |
Mon, 11 February 2008 02:27  |
Eclipse User |
|
|
|
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 10:17  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.02606 seconds