Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Collection whose elements are all different(What is the best way to determine whether the elements in a collection are all different?)
[Acceleo] Collection whose elements are all different [message #895091] Wed, 11 July 2012 16:35 Go to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 46
Registered: July 2010
Member
Hello

This question might be trivial for many. I found a solution, but didn't feel comfortable with it.

I want to validate that the names assigned to states in a state machine are different to each other. I wrote this query:

[query public validateStatesNames(aStateMachine: StateMachine): Boolean =
	aStateMachine.getStates()
	->collect(s: State | s.name)
	->asSet()
	->size() = aStateMachine.getNumberStates()
/]


where getStates() returns a collection of instances of State in the receiving instance of StateMachine, and getNumberStates() returns the number of elements on this collection of states.

Do you know about an undocumented operation that performs the evaluation I need? Do you know about a more elegant solution?

Thank you very much.


/TB
Re: [Acceleo] Collection whose elements are all different [message #895913 is a reply to message #895091] Mon, 16 July 2012 13:34 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

You could use ".name" to make it a bit shorter but otherwise I don't think that we have something that could help you more than that.
[query public validateStatesNames(aStateMachine: StateMachine): Boolean =
	aStateMachine.getStates()
	.name
	->asSet()
	->size() = aStateMachine.getNumberStates()
/]


Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo



[Updated on: Mon, 16 July 2012 13:35]

Report message to a moderator

Re: [Acceleo] Collection whose elements are all different [message #895927 is a reply to message #895913] Mon, 16 July 2012 14:08 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi

I suspect that aStateMachine.getNumberStates() is redundant.

let allStates : Set(State) = aStateMachine.getStates() in
allStates.name->asSet()->size() = allStates->size()

(the redundant " : Set(State) " is heading for optionality.)

Regards

Ed Willink


On 16/07/2012 14:34, Stephane Begaudeau wrote:
> Hi,
>
> You could use ".name" to make it a bit shorter but otherwise I don't
> think that we have something that could help you more than that.
> [query public validateStatesNames(aStateMachine: StateMachine): Boolean =
> aStateMachine.getStates()
> .name
> ->asSet()
> ->size() = aStateMachine.getNumberStates()
> /]
>
> Regards,
>
> Stephane Begaudeau, Obeo
>
> --
> Twitter: http://twitter.com/#!/sbegaudeau & http://twitter.com/#!/acceleo
> Google+: https://plus.google.com/u/0/105625286543794908607/ &
> https://plus.google.com/u/0/114651471803085159652/
> Blog: http://stephanebegaudeau.tumblr.com
> Acceleo Documentation: http://docs.obeonetwork.com/acceleo
Previous Topic:xpand and aspects
Next Topic:Retrieve target folder during generation
Goto Forum:
  


Current Time: Wed Nov 26 13:00:13 GMT 2014

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

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