Home » Modeling » OCL » Looking for help about collections manipulation
Looking for help about collections manipulation [message #70109] |
Tue, 28 April 2009 23:48  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
--=-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. How about this:<BR>
<BR>
context SequenceHelper<BR>
def: reorganize(seq : Sequence(OclAny)) : Sequence(Sequence(OclAny)) =<BR>
if seq->size() = 1 then<BR>
Sequence{seq}<BR>
else<BR>
seq->subSequence(2, seq->size())->collectNested(nested|<BR>
reorganize(nested)->collect(next | Sequence{seq->at(1)}->union(next)))<BR>
endif<BR>
<BR>
This defines a recursive operation on a fictitious "SequenceHelper" 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. 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).<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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
--=-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. I must say that I'm surprised :-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 é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
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>
--=-dBsWFDFdxahDLRKx5LX4--
|
|
|
Goto Forum:
Current Time: Sat Jul 05 17:20:39 EDT 2025
Powered by FUDForum. Page generated in 0.03870 seconds
|