Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to populate a Map of List ?
How to populate a Map of List ? [message #941546] Fri, 12 October 2012 16:26 Go to next message
David Michonneau is currently offline David MichonneauFriend
Messages: 85
Registered: July 2009
Member
I have modeled a map of <String,List> in my ecore based on the wiki (http://wiki.eclipse.org/EMF/FAQ#How_do_I_create_a_Map_in_EMF.3F), it has generated the code correctly, but now I don't see how to populate it.

Indeed the map values are EList, and I didn't find any corresponding feature for it. How to create it?

I get this method in the map impl class:
public EMap<String, EList<MyClass>> getEMap()

Now when I want to put something in it, I will do:
a.put("key", value);

the question is: how do I create an empty EList<MyClass> for value?

Thanks,

David
Re: How to populate a Map of List ? [message #941559 is a reply to message #941546] Fri, 12 October 2012 16:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
David,

Comments below.
On 12/10/2012 6:26 PM, David Michonneau wrote:
> I have modeled a map of <String,List> in my ecore based on the wiki
> (http://wiki.eclipse.org/EMF/FAQ#How_do_I_create_a_Map_in_EMF.3F), it
> has generated the code correctly, but now I don't see how to populate it.
>
> Indeed the map values are EList, and I didn't find any corresponding
> feature for it. How to create it?
>
> I get this method in the map impl class:
> public EMap<String, EList<MyClass>> getEMap()
>
> Now when I want to put something in it, I will do:
> a.put("key", value);
>
> the question is: how do I create an empty EList<MyClass> for value?
ECollections.emptyList(); a put will copy that into the value feature of
the map entry, essentially creating a map entry with an empty value
list. Or create a new BasicEList, populated it with MyClass instances
and use put("key", list), which will copy the list into the value
feature of the map entry.
>
> Thanks,
>
> David


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to populate a Map of List ? [message #942510 is a reply to message #941559] Sat, 13 October 2012 15:47 Go to previous message
David Michonneau is currently offline David MichonneauFriend
Messages: 85
Registered: July 2009
Member
Cool, I didn't know of this API. I used a much more complex way:
BasicEMap.Entry<String,EList<MyClass>> entry = (BasicEMap.Entry<String,EList<MyClass>)EcoreUtil.create(MyPackage.Literals.MY_MAP );
entry.setKey("key");
value = entry.getValue(); // list auto-created by emf
map.add(entry);

but your solution is far simpler!

Thanks,

David
Previous Topic:Defining which derived class a feature from an abstract class shall use
Next Topic:hashcode and Map (non mutable case)
Goto Forum:
  


Current Time: Fri Apr 26 23:01:59 GMT 2024

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

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

Back to the top