Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Removing duplicate in collection(How to remove duplicate descriptions of collections)
[Acceleo] Removing duplicate in collection [message #897655] Tue, 24 July 2012 23:13 Go to next message
Wagner de Andrade Perin is currently offline Wagner de Andrade PerinFriend
Messages: 2
Registered: July 2012
Junior Member
Hi.

I am a beginner in Acceleo and have a "simple" problem.

I write this code:
primeiraOrdem(Conceito, Consulta) :-
[for (elemento : Componentes | aMapaConceitual.elementos->sortedBy(descricao))]
	[if (elemento.oclIsTypeOf(Relacao))]
	[elemento.descricao/](Conceito, Consulta),
	[/if]
[/for]

And i get this results:
primeiraOrdem(Conceito, Consulta) :-
	e(Conceito, Consulta),
	podeestar(Conceito, Consulta),
	podeser(Conceito, Consulta),
	quandoesta(Conceito, Consulta),
	quandoesta(Conceito, Consulta),
	tem(Conceito, Consulta),
	tem(Conceito, Consulta).


My question is: "How can I remove the lines that are worded "duplicate" (case of 'quandoesta' and 'tem')?"

I tried everything I could think but not got successful.

Excuse my poor English.

Thank you already.
Re: [Acceleo] Removing duplicate in collection [message #897671 is a reply to message #897655] Wed, 25 July 2012 05:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4150
Registered: July 2009
Senior Member
Hi

Set is the usual way to force uniqueness, with isUnique() helpful in
more complicated scenarios.

You can just change to loop over your names reduced to a set of their values

[for (descricao: String|
aMapaConceitual.elementos->select(oclIsTypeOf(Relacao)).descricao->asSet()->sortedBy(descricao
| descricao))]
[descricao/](Conceito, Consulta),
[/for]

oclIsKindOf is generally better than oclIsTypeOf, in which case filter()
would be better. (In Juno OCL adds selectByType and selectByKind as well).

Regards

Ed Willink

On 25/07/2012 00:13, Wagner de Andrade Perin wrote:
> Hi.
>
> I am a beginner in Acceleo and have a "simple" problem.
>
> I write this code:
>
> primeiraOrdem(Conceito, Consulta) :-
> [for (elemento : Componentes |
> aMapaConceitual.elementos->sortedBy(descricao))]
> [if (elemento.oclIsTypeOf(Relacao))]
> [elemento.descricao/](Conceito, Consulta),
> [/if]
> [/for]
>
> And i get this results:
> primeiraOrdem(Conceito, Consulta) :-
> e(Conceito, Consulta),
> podeestar(Conceito, Consulta),
> podeser(Conceito, Consulta),
> quandoesta(Conceito, Consulta),
> quandoesta(Conceito, Consulta),
> tem(Conceito, Consulta),
> tem(Conceito, Consulta).
>
> My question is: "How can I remove the lines that are worded
> "duplicate" (case of 'quandoesta' and 'tem')?"
>
> I tried everything I could think but not got successful.
>
> Excuse my poor English.
>
> Thank you already.
icon14.gif  Re: [Acceleo] Removing duplicate in collection [message #897993 is a reply to message #897671] Wed, 25 July 2012 15:07 Go to previous message
Wagner de Andrade Perin is currently offline Wagner de Andrade PerinFriend
Messages: 2
Registered: July 2012
Junior Member
Thank you so much.

It worked perfectly.

I tried using the "asSet" but with a collection of "Relacao" and not their "descricao".

Now I understand how to use it.

I'm very grateful for your help!
Previous Topic:XPand2 extension problem
Next Topic:[Acceleo] Class 'System' is not found or is abstract
Goto Forum:
  


Current Time: Sat Nov 22 10:37:46 GMT 2014

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

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