Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Building a Map Dynamically
Building a Map Dynamically [message #1566016] Thu, 15 January 2015 16:23 Go to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
I want to build a Map dynamically from within a helper def. This Map will help later in the transformation rules for mapping local namespace prefixes to non-local namespace prefixes. It seems very difficult to build a map dynamically in ATL.

I started as follows:

helper def : prefixMap : Map(String,String) = MM1!X.allInstances()->select(e|MM1!Y.allInstances()->exists(f|f.name=e.name))->collect(e|Map{(e.name,MM1!Y.allInstances()->select(f|f.name=e.name)->first().prefix.name)});

or put simpler to show the issue:
helper def : prefixMap : Map(String,String) = MM1!X.allInstances()->collect(e|Map{(e.name,e.name)});

but this results in a Sequence containing a nested Map for each entry. I want a single Map containing pairs of namespace prefixes for each entry e.g. Sequence {Map{(a, az), (b, bz)}}

Thanks,
Ronan

[Updated on: Thu, 15 January 2015 16:23]

Report message to a moderator

Re: Building a Map Dynamically [message #1574982 is a reply to message #1566016] Tue, 20 January 2015 15:03 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Use iterate() with Map::including(), e.g.:

--- Returns the existing EMRS!AbstractUser for the given INSS.
helper def : existingUsersByINSS : Map(String,EMRS!AbstractUser) =
	thisModule.existingUsersWithPersons->iterate(u; acc : Map(String,EMRS!AbstractUser) = Map{} |
		if u.person.inss.oclIsUndefined() or u.person.inss.isEmpty() then
			acc
		else
			acc->including(u.person.inss, u)
		endif
	);


Cheers,
Dennis
Re: Building a Map Dynamically [message #1576766 is a reply to message #1574982] Wed, 21 January 2015 14:10 Go to previous message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Ok, great!
Thanks,
Ronan
Previous Topic:Is it possible to to save model in BPEL?
Next Topic:thisModule.resolveTemp() returns OclUndefined
Goto Forum:
  


Current Time: Sat Apr 20 01:07:07 GMT 2024

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

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

Back to the top