Building a Map Dynamically [message #1566016] |
Thu, 15 January 2015 16:23 |
Ronan B 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 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03217 seconds