Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » MAP
MAP [message #1447504] Sat, 18 October 2014 11:59 Go to next message
Ralf Buschermoehle is currently offline Ralf BuschermoehleFriend
Messages: 8
Registered: August 2013
Junior Member
Hi,

I created a MAP according to http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_create_a_Map_in_EMF.3F.

Please find a screenshot of the emf model part attached (map.jpg). When I try to generate model code EMF complains about missing Dimensions (see map2.jpg).

Opening the file at the line with the error shows:

EMap<int, int> getTest();

// test is the attribute pointing to the MapEntries.

What am I missing?

Greetings,

Ralf
  • Attachment: map.jpg
    (Size: 11.31KB, Downloaded 82 times)
  • Attachment: map2.jpg
    (Size: 50.34KB, Downloaded 87 times)
Re: MAP [message #1447518 is a reply to message #1447504] Sat, 18 October 2014 12:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30687
Registered: July 2009
Senior Member
Ralf,

Primitive types can't be type arguments so you'd need to model this with
the wrapper types, i.e., EIntegerObject. I.e., you want to generate
EMap<Integer, Integer>, not EMap<int, int>. There should really be a
constraint that checks for this so you'd know before you tried to
generate that it's bogus.


On 18/10/2014 1:59 PM, Ralf Buschermoehle wrote:
> Hi,
>
> I created a MAP according to http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_create_a_Map_in_EMF.3F.
>
> Please find a screenshot of the emf model part attached (map.jpg). When I try to generate model code EMF complains about missing Dimensions (see map2.jpg).
>
> Opening the file at the line with the error shows:
>
> EMap<int, int> getTest();
>
> // test is the attribute pointing to the MapEntries.
>
> What am I missing?
>
> Greetings,
>
> Ralf
>
Re: MAP [message #1447541 is a reply to message #1447518] Sat, 18 October 2014 13:23 Go to previous messageGo to next message
Ralf Buschermoehle is currently offline Ralf BuschermoehleFriend
Messages: 8
Registered: August 2013
Junior Member
Ok, thanks! Smile
Re: MAP [message #1447594 is a reply to message #1447518] Sat, 18 October 2014 15:20 Go to previous messageGo to next message
Ralf Buschermoehle is currently offline Ralf BuschermoehleFriend
Messages: 8
Registered: August 2013
Junior Member
Hi,

I have now an EMap<Integer, EList<Integer>> ... or more precisely I have a list of BasicEMap.Entry<Integer,EList<Integer>> entries, right?

How can/should I check/add entries? In source code ... setting key / value like this fails ...

Object test = eObject.eGet(someEStructFeature);
EcoreEList.Dynamic<BasicEMap.Entry<Integer,EList<Integer>>> listOfEntries = (Dynamic<org.eclipse.emf.common.util.BasicEMap.Entry<Integer, EList<Integer>>>) test;

// creating a new entry

DynamicEObjectImpl.BasicEMapEntry<Integer,EList<Integer>> newEntry = new DynamicEObjectImpl.BasicEMapEntry<Integer, EList<Integer>>();

BasicEList<Integer> newList = new BasicEList<Integer>(1);
newEntry.setValue(newList);
newEntry.setKey(new Integer(1));

listOfEntries.add(newEntry);

And on the other side ... I need to compare all keys (manually) to retrieve the "right" value, right?

Greetings,

Ralf
Re: MAP [message #1447643 is a reply to message #1447594] Sat, 18 October 2014 17:10 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30687
Registered: July 2009
Senior Member
Ralf,

Comments below.

On 18/10/2014 5:20 PM, Ralf Buschermoehle wrote:
> Hi,
>
> I have now an EMap<Integer, EList<Integer>> ... or more precisely I
> have a list of BasicEMap.Entry<Integer,EList<Integer>> entries, right?
In terms of implementation details, yes.
>
> How can/should I check/add entries? In source code ... setting key /
> value like this fails ...
Use the EMap API. There's even the
org.eclipse.emf.common.util.EMap.map() view (read/write) so you can
treat it exactly as a java.util.Map.
>
> Object test = eObject.eGet(someEStructFeature);
> EcoreEList.Dynamic<BasicEMap.Entry<Integer,EList<Integer>>>
> listOfEntries =
> (Dynamic<org.eclipse.emf.common.util.BasicEMap.Entry<Integer,
> EList<Integer>>>) test;
Don't cast to implementation specific details. It's just an EMap.
>
> // creating a new entry
>
> DynamicEObjectImpl.BasicEMapEntry<Integer,EList<Integer>> newEntry =
> new DynamicEObjectImpl.BasicEMapEntry<Integer, EList<Integer>>();
Given you have a generated model, this isn't going to work. I.e., you
have a generate map entry implementation and that must be used.
>
> BasicEList<Integer> newList = new BasicEList<Integer>(1);
> newEntry.setValue(newList);
> newEntry.setKey(new Integer(1));
>
> listOfEntries.add(newEntry);
>
> And on the other side ... I need to compare all keys (manually) to
> retrieve the "right" value, right?
Ecore itself has an EMap for EAnnotation.details. We just call
eAnnotation.getDetails().get(key) and get a String value back or call
eAnnotation.getDetails.put(key, value) and put a String value in. It's
just a map; there are very few places where you need to be concerned
with lower level details. So it makes me wonder why you're asking in
the first place...
>
> Greetings,
>
> Ralf
Previous Topic:Performance problem: how to speed up loadPackage() in EPackageImpl class
Next Topic:[CDO] Persisting CDORevisionCache to filesystem to improve user experience
Goto Forum:
  


Current Time: Mon Dec 09 09:39:55 GMT 2019

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

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

Back to the top