Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Galileo, XPAND] Select just one Object with the same name
[Galileo, XPAND] Select just one Object with the same name [message #871951] Tue, 15 May 2012 03:47 Go to next message
Ricardo Ben Amor is currently offline Ricardo Ben Amor
Messages: 51
Registered: March 2012
Member
Hi,

I have a little problem for making an operation with my XPAND project.

The problem is the following :

I get some informations from an XML files, I recover a list of information.

In that list, I have some name which are the same. Example :

In my list I have 4 or 5 times the name "ID4". My answer is, how I can just take one time the name "ID4", because i don't need him 4-5 times because is the same.

I just want him one time.

But, i don't know how i can do, have you an idea about my subjet maybe?

Thanks in advance,

Best Regards,
Re: [Galileo, XPAND] Select just one Object with the same name [message #871958 is a reply to message #871951] Tue, 15 May 2012 04:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5840
Registered: July 2009
Senior Member
Hi what about calling toSet on a list
Re: [Galileo, XPAND] Select just one Object with the same name [message #872092 is a reply to message #871958] Tue, 15 May 2012 08:50 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben Amor
Messages: 51
Registered: March 2012
Member
I don't understand what are you saying...

I mean, i have a list of my numbers "4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6 etc....". When I take the list, i don't have the expression ToSet on a list.

The only expression I have are : toString(), toInteger, upTo(Integer), upTo(Integer,Integer).
Re: [Galileo, XPAND] Select just one Object with the same name [message #872111 is a reply to message #872092] Tue, 15 May 2012 09:39 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben Amor
Messages: 51
Registered: March 2012
Member
Sorry, I resolve my problem.

Indeed the expression toSet() was available but i have mistake about the argument I use.

Now it's work.

Thanks you Christian
Re: [Galileo, XPAND] Select just one Object with the same name [message #872117 is a reply to message #872092] Tue, 15 May 2012 09:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5840
Registered: July 2009
Senior Member
Hi something like {1,2,3,4,4,5}.toSet() doesn't work?
Re: [Galileo, XPAND] Select just one Object with the same name [message #872124 is a reply to message #872117] Tue, 15 May 2012 10:02 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben Amor
Messages: 51
Registered: March 2012
Member
Yes, I have do some researsch in the Help and I find that expression "{1,2,3,4,4,5}.toSet()". I try with my list and it works properly. Thanks again
Re: [Galileo, XPAND] Select just one Object with the same name [message #872197 is a reply to message #872124] Tue, 15 May 2012 12:28 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben Amor
Messages: 51
Registered: March 2012
Member
Like I say it works but the result into my application not.

I have to look about an another strategy. Could be possible for EACH ID : 4,4,4,4,4,4 or ,6,6,6,6,6,6 to add an enumeration.

I'm explaining, this ID are the same and i want to make an difference between the 3 or 4 of them. So I had to each ID a letter or something to make the difference.

The resultat could be :

ID4_a
ID4_b
ID4_C
ID6_a
ID6_b
etc.....

Regards
Re: [Galileo, XPAND] Select just one Object with the same name [message #872207 is a reply to message #872197] Tue, 15 May 2012 13:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5840
Registered: July 2009
Senior Member
Hm,

quite imperative stuff for a functional language. if you are simply interested for the names why dont you
(1) collect all names
(2) then call toSet on them
(3) and write a second extension that gives you the first object with a matching name

the name postfix might be solved more easy if you simply count up the number no matter what the prefix is

[Updated on: Tue, 15 May 2012 17:38]

Report message to a moderator

Re: [Galileo, XPAND] Select just one Object with the same name [message #872474 is a reply to message #872207] Wed, 16 May 2012 03:36 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben Amor
Messages: 51
Registered: March 2012
Member
Hi,

I don't see how to use that in my FOREACH loop.

Like you see, the variable "SlotID" is a list of Integer. Some Integer a repeat 4 or 5 times.

I need to use the all integer but just make a difference between the same number.

With your reply from yesterdy, I try this morning to do some test but i don't see how to do.

«FOREACH  topLevelPackages...slotId AS SlotID ITERATOR SlotIDCounter-»

«IF (InputOutput...get(SlotIDCounter.counter0).toString()) == "IN"-»
const Fr_rx_buffer_slot_«SlotID»_cfg =
{
   «SlotID»,                    // Receive frame ID
};
«ELSEIF (InputOutput...get(SlotIDCounter.counter0).toString()) == "OUT"-»
const Fr_tx_buffer_slot_«SlotID»_cfg =
{
   «SlotID»,                           // Transmit frame ID
   «Length.frameLength.get(SlotIDCounter.counter0)»,          // Payload length
};
«ENDIF-»
«ENDFOREACH-»


Regards,
Re: [Galileo, XPAND] Select just one Object with the same name [message #872563 is a reply to message #872474] Wed, 16 May 2012 06:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5840
Registered: July 2009
Senior Member
hi, does the order play a role?
Re: [Galileo, XPAND] Select just one Object with the same name [message #872566 is a reply to message #872563] Wed, 16 May 2012 07:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5840
Registered: July 2009
Senior Member
if not the following extension might help


List[String] handle(List[Integer] list) :
	list.toSet().collect(i|list.select(e|e == i).index(0)).flatten();
	
List[String ]index(List[Integer] list, int start) :
	list.isEmpty ? {} : ({(list.get(0).toString() + "_" + start.toString())}.addAll(index(list.withoutFirst(),start+1))) 
	;
Re: [Galileo, XPAND] Select just one Object with the same name [message #872616 is a reply to message #872566] Wed, 16 May 2012 09:16 Go to previous message
Ricardo Ben Amor is currently offline Ricardo Ben Amor
Messages: 51
Registered: March 2012
Member
Hi,

Thanks Christian. It is exactly what I want to do (function handle). I noticed that the xpand langage is no enough when you want to do something specific. I'm going to work a little more with xtend langage, because their is very helpful.

Thanks again,
Previous Topic:XPand non containment references
Next Topic:[Acceleo] How to change the editor colours
Goto Forum:
  


Current Time: Wed Apr 16 07:02:10 EDT 2014

Powered by FUDForum. Page generated in 0.02227 seconds