Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Looking for help about collections manipulation
Looking for help about collections manipulation [message #70109] Tue, 28 April 2009 23:48 Go to next message
Guillaume Gauffre is currently offline Guillaume Gauffre
Messages: 65
Registered: July 2009
Member
Hi,

I using ocl language as part of ATL language and I don't find a solution
to my problem, but maybe an experimented ocl user may find the solution.

a result of an operation gives me this structure of collections, where
1,2,3 and 4 are elements :
Sequence {
1
Sequence {
2,
Sequence {
3
},
Sequence {
4
}
},
Sequence {
3
},
Sequence {
4
}
}

I'm looking for an operation which will give this reorganisation :
Sequence {
Sequence {
1,
2,
3
}
Sequence {
1,
2,
4
}
Sequence {
1,
3
},
Sequence {
1,
4
}
}

Does anybody see the way I could achieve it ?

Thanks,

Guillaume
Re: Looking for help about collections manipulation [message #70131 is a reply to message #70109] Thu, 30 April 2009 09:02 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 776
Registered: July 2009
Senior Member
--=-SSqrAoBI2jnWUtm8y0/5
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

H, Guillaume,

Obviously, the OCL Standard Library doesn't have an operation that does
this in one step, but I can try to formulate something. How about this:

context SequenceHelper
def: reorganize(seq : Sequence(OclAny)) : Sequence(Sequence(OclAny)) =
if seq->size() = 1 then
Sequence{seq}
else
seq->subSequence(2, seq->size())->collectNested(nested|
reorganize(nested)->collect(next |
Sequence{seq->at(1)}->union(next)))
endif

This defines a recursive operation on a fictitious "SequenceHelper"
class (you can choose any in your model).

Note, however, that this will only work with the changed semantics
currently adopted for the upcoming OCL 2.1 specification. In
particular, it requires that collection types also conform to OclAny, as
do class and primitive types (in OCL 2.0, collection types are
completely distinct). In the current Eclipse OCL implementation, you
shouldn't even be able to create collections that are a mix of objects
and nested collections. Certainly, you won't be able to declare a
collection type that can encompass objects and collections, nor parse an
expression that attempts to add a collection to a Collection(OclAny).

HTH,

Christian


On Wed, 2009-04-29 at 05:48 +0200, Guillaume wrote:

> Hi,
>
> I using ocl language as part of ATL language and I don't find a solution
> to my problem, but maybe an experimented ocl user may find the solution.
>
> a result of an operation gives me this structure of collections, where
> 1,2,3 and 4 are elements :
> Sequence {
> 1
> Sequence {
> 2,
> Sequence {
> 3
> },
> Sequence {
> 4
> }
> },
> Sequence {
> 3
> },
> Sequence {
> 4
> }
> }
>
> I'm looking for an operation which will give this reorganisation :
> Sequence {
> Sequence {
> 1,
> 2,
> 3
> }
> Sequence {
> 1,
> 2,
> 4
> }
> Sequence {
> 1,
> 3
> },
> Sequence {
> 1,
> 4
> }
> }
>
> Does anybody see the way I could achieve it ?
>
> Thanks,
>
> Guillaume

--=-SSqrAoBI2jnWUtm8y0/5
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
H, Guillaume,<BR>
<BR>
Obviously, the OCL Standard Library doesn't have an operation that does this in one step, but I can try to formulate something.&nbsp; How about this:<BR>
<BR>
context SequenceHelper<BR>
def: reorganize(seq : Sequence(OclAny)) : Sequence(Sequence(OclAny)) =<BR>
&nbsp;&nbsp;&nbsp; if seq-&gt;size() = 1 then<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sequence{seq}<BR>
&nbsp;&nbsp;&nbsp; else<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; seq-&gt;subSequence(2, seq-&gt;size())-&gt;collectNested(nested|<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reorganize(nested)-&gt;collect(next | Sequence{seq-&gt;at(1)}-&gt;union(next)))<BR>
&nbsp;&nbsp;&nbsp; endif<BR>
<BR>
This defines a recursive operation on a fictitious &quot;SequenceHelper&quot; class (you can choose any in your model).<BR>
<BR>
Note, however, that this will only work with the changed semantics currently adopted for the upcoming OCL 2.1 specification.&nbsp; In particular, it requires that collection types also conform to OclAny, as do class and primitive types (in OCL 2.0, collection types are completely distinct).&nbsp; In the current Eclipse OCL implementation, you shouldn't even be able to create collections that are a mix of objects and nested collections.&nbsp; Certainly, you won't be able to declare a collection type that can encompass objects and collections, nor parse an expression that attempts to add a collection to a Collection(OclAny).<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Wed, 2009-04-29 at 05:48 +0200, Guillaume wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi,

I using ocl language as part of ATL language and I don't find a solution
to my problem, but maybe an experimented ocl user may find the solution.

a result of an operation gives me this structure of collections, where
1,2,3 and 4 are elements :
Sequence {
1
Sequence {
2,
Sequence {
3
},
Sequence {
4
}
},
Sequence {
3
},
Sequence {
4
}
}

I'm looking for an operation which will give this reorganisation :
Sequence {
Sequence {
1,
2,
3
}
Sequence {
1,
2,
4
}
Sequence {
1,
3
},
Sequence {
1,
4
}
}

Does anybody see the way I could achieve it ?

Thanks,

Guillaume
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-SSqrAoBI2jnWUtm8y0/5--
Re: Looking for help about collections manipulation [message #70152 is a reply to message #70131] Sun, 03 May 2009 20:10 Go to previous messageGo to next message
Guillaume Gauffre is currently offline Guillaume Gauffre
Messages: 65
Registered: July 2009
Member
It works !!
Thanks a lot.
Concerning your note, since my routine is part of a ATL transformation,
there is no problem. Primitive and Collection types can be mixed in a
same collection.

Christian W. Damus a écrit :
> H, Guillaume,
>
> Obviously, the OCL Standard Library doesn't have an operation that does
> this in one step, but I can try to formulate something. How about this:
>
> context SequenceHelper
> def: reorganize(seq : Sequence(OclAny)) : Sequence(Sequence(OclAny)) =
> if seq->size() = 1 then
> Sequence{seq}
> else
> seq->subSequence(2, seq->size())->collectNested(nested|
> reorganize(nested)->collect(next |
> Sequence{seq->at(1)}->union(next)))
> endif
>
> This defines a recursive operation on a fictitious "SequenceHelper"
> class (you can choose any in your model).
>
> Note, however, that this will only work with the changed semantics
> currently adopted for the upcoming OCL 2.1 specification. In
> particular, it requires that collection types also conform to OclAny, as
> do class and primitive types (in OCL 2.0, collection types are
> completely distinct). In the current Eclipse OCL implementation, you
> shouldn't even be able to create collections that are a mix of objects
> and nested collections. Certainly, you won't be able to declare a
> collection type that can encompass objects and collections, nor parse an
> expression that attempts to add a collection to a Collection(OclAny).
>
> HTH,
>
> Christian
>
>
> On Wed, 2009-04-29 at 05:48 +0200, Guillaume wrote:
>> Hi,
>>
>> I using ocl language as part of ATL language and I don't find a solution
>> to my problem, but maybe an experimented ocl user may find the solution.
>>
>> a result of an operation gives me this structure of collections, where
>> 1,2,3 and 4 are elements :
>> Sequence {
>> 1
>> Sequence {
>> 2,
>> Sequence {
>> 3
>> },
>> Sequence {
>> 4
>> }
>> },
>> Sequence {
>> 3
>> },
>> Sequence {
>> 4
>> }
>> }
>>
>> I'm looking for an operation which will give this reorganisation :
>> Sequence {
>> Sequence {
>> 1,
>> 2,
>> 3
>> }
>> Sequence {
>> 1,
>> 2,
>> 4
>> }
>> Sequence {
>> 1,
>> 3
>> },
>> Sequence {
>> 1,
>> 4
>> }
>> }
>>
>> Does anybody see the way I could achieve it ?
>>
>> Thanks,
>>
>> Guillaume
Re: Looking for help about collections manipulation [message #70172 is a reply to message #70152] Mon, 04 May 2009 08:33 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 776
Registered: July 2009
Senior Member
--=-dBsWFDFdxahDLRKx5LX4
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi, Guillaume,

Wow. I must say that I'm surprised :-D

I'm glad it worked for you! Good on ATL.

Christian


On Mon, 2009-05-04 at 02:10 +0200, Guillaume wrote:

> It works !!
> Thanks a lot.
> Concerning your note, since my routine is part of a ATL transformation,=20
> there is no problem. Primitive and Collection types can be mixed in a=20
> same collection.
>=20
> Christian W. Damus a =C3=A9crit :
> > H, Guillaume,
> >=20
> > Obviously, the OCL Standard Library doesn't have an operation that does=
=20
> > this in one step, but I can try to formulate something. How about this=
:
> >=20
> > context SequenceHelper
> > def: reorganize(seq : Sequence(OclAny)) : Sequence(Sequence(OclAny)) =
=3D
> > if seq->size() =3D 1 then
> > Sequence{seq}
> > else
> > seq->subSequence(2, seq->size())->collectNested(nested|
> > reorganize(nested)->collect(next |=20
> > Sequence{seq->at(1)}->union(next)))
> > endif
> >=20
> > This defines a recursive operation on a fictitious "SequenceHelper"=20
> > class (you can choose any in your model).
> >=20
> > Note, however, that this will only work with the changed semantics=20
> > currently adopted for the upcoming OCL 2.1 specification. In=20
> > particular, it requires that collection types also conform to OclAny, a=
s=20
> > do class and primitive types (in OCL 2.0, collection types are=20
> > completely distinct). In the current Eclipse OCL implementation, you=20
> > shouldn't even be able to create collections that are a mix of objects=20
> > and nested collections. Certainly, you won't be able to declare a=20
> > collection type that can encompass objects and collections, nor parse a=
n=20
> > expression that attempts to add a collection to a Collection(OclAny).
> >=20
> > HTH,
> >=20
> > Christian
> >=20
> >=20
> > On Wed, 2009-04-29 at 05:48 +0200, Guillaume wrote:
> >> Hi,
> >>
> >> I using ocl language as part of ATL language and I don't find a soluti=
on=20
> >> to my problem, but maybe an experimented ocl user may find the solutio=
n.
> >>
> >> a result of an operation gives me this structure of collections, where=
=20
> >> 1,2,3 and 4 are elements :
> >> Sequence {
> >> 1
> >> Sequence {
> >> 2,
> >> Sequence {
> >> 3
> >> },
> >> Sequence {
> >> 4
> >> }
> >> },
> >> Sequence {
> >> 3
> >> },
> >> Sequence {
> >> 4
> >> }
> >> }
> >>
> >> I'm looking for an operation which will give this reorganisation :
> >> Sequence {
> >> Sequence {
> >> 1,
> >> 2,
> >> 3
> >> }
> >> Sequence {
> >> 1,
> >> 2,
> >> 4
> >> }
> >> Sequence {
> >> 1,
> >> 3
> >> },
> >> Sequence {
> >> 1,
> >> 4
> >> }
> >> }
> >>
> >> Does anybody see the way I could achieve it ?
> >>
> >> Thanks,
> >>
> >> Guillaume

--=-dBsWFDFdxahDLRKx5LX4
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Guillaume,<BR>
<BR>
Wow.&nbsp; I must say that I'm surprised&nbsp; :-D<BR>
<BR>
I'm glad it worked for you! Good on ATL.<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Mon, 2009-05-04 at 02:10 +0200, Guillaume wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
It works !!
Thanks a lot.
Concerning your note, since my routine is part of a ATL transformation,
there is no problem. Primitive and Collection types can be mixed in a
same collection.

Christian W. Damus a &#233;crit :
&gt; H, Guillaume,
&gt;
&gt; Obviously, the OCL Standard Library doesn't have an operation that does
&gt; this in one step, but I can try to formulate something. How about this:
&gt;
&gt; context SequenceHelper
&gt; def: reorganize(seq : Sequence(OclAny)) : Sequence(Sequence(OclAny)) =
&gt; if seq-&gt;size() = 1 then
&gt; Sequence{seq}
&gt; else
&gt; seq-&gt;subSequence(2, seq-&gt;size())-&gt;collectNested(nested|
&gt; reorganize(nested)-&gt;collect(next |
&gt; Sequence{seq-&gt;at(1)}-&gt;union(next)))
&gt; endif
&gt;
&gt; This defines a recursive operation on a fictitious &quot;SequenceHelper&quot;
&gt; class (you can choose any in your model).
&gt;
&gt; Note, however, that this will only work with the changed semantics
&gt; currently adopted for the upcoming OCL 2.1 specification. In
&gt; particular, it requires that collection types also conform to OclAny, as
&gt; do class and primitive types (in OCL 2.0, collection types are
&gt; completely distinct). In the current Eclipse OCL implementation, you
&gt; shouldn't even be able to create collections that are a mix of objects
&gt; and nested collections. Certainly, you won't be able to declare a
&gt; collection type that can encompass objects and collections, nor parse an
&gt; expression that attempts to add a collection to a Collection(OclAny).
&gt;
&gt; HTH,
&gt;
&gt; Christian
&gt;
&gt;
&gt; On Wed, 2009-04-29 at 05:48 +0200, Guillaume wrote:
&gt;&gt; Hi,
&gt;&gt;
&gt;&gt; I using ocl language as part of ATL language and I don't find a solution
&gt;&gt; to my problem, but maybe an experimented ocl user may find the solution.
&gt;&gt;
&gt;&gt; a result of an operation gives me this structure of collections, where
&gt;&gt; 1,2,3 and 4 are elements :
&gt;&gt; Sequence {
&gt;&gt; 1
&gt;&gt; Sequence {
&gt;&gt; 2,
&gt;&gt; Sequence {
&gt;&gt; 3
&gt;&gt; },
&gt;&gt; Sequence {
&gt;&gt; 4
&gt;&gt; }
&gt;&gt; },
&gt;&gt; Sequence {
&gt;&gt; 3
&gt;&gt; },
&gt;&gt; Sequence {
&gt;&gt; 4
&gt;&gt; }
&gt;&gt; }
&gt;&gt;
&gt;&gt; I'm looking for an operation which will give this reorganisation :
&gt;&gt; Sequence {
&gt;&gt; Sequence {
&gt;&gt; 1,
&gt;&gt; 2,
&gt;&gt; 3
&gt;&gt; }
&gt;&gt; Sequence {
&gt;&gt; 1,
&gt;&gt; 2,
&gt;&gt; 4
&gt;&gt; }
&gt;&gt; Sequence {
&gt;&gt; 1,
&gt;&gt; 3
&gt;&gt; },
&gt;&gt; Sequence {
&gt;&gt; 1,
&gt;&gt; 4
&gt;&gt; }
&gt;&gt; }
&gt;&gt;
&gt;&gt; Does anybody see the way I could achieve it ?
&gt;&gt;
&gt;&gt; Thanks,
&gt;&gt;
&gt;&gt; Guillaume
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-dBsWFDFdxahDLRKx5LX4--
Previous Topic:abstract derive function
Next Topic:OCL and Ecore object relationships
Goto Forum:
  


Current Time: Fri Aug 29 06:17:48 EDT 2014

Powered by FUDForum. Page generated in 0.08937 seconds