Skip to main content



      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 12:35 Go to next message
Eclipse UserFriend
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.
Re: [Acceleo] Collection whose elements are all different [message #895913 is a reply to message #895091] Mon, 16 July 2012 09:34 Go to previous messageGo to next message
Eclipse UserFriend
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 09:35] by Moderator

Re: [Acceleo] Collection whose elements are all different [message #895927 is a reply to message #895913] Mon, 16 July 2012 10:08 Go to previous message
Eclipse UserFriend
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:[XPAND]Transform XML to TEXT
Goto Forum:
  


Current Time: Wed Jul 23 00:29:02 EDT 2025

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

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

Back to the top