Skip to main content



      Home
Home » Modeling » EMF » MAP
MAP [message #1447504] Sat, 18 October 2014 07:59 Go to next message
Eclipse UserFriend
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 161 times)
  • Attachment: map2.jpg
    (Size: 50.34KB, Downloaded 175 times)
Re: MAP [message #1447518 is a reply to message #1447504] Sat, 18 October 2014 08:24 Go to previous messageGo to next message
Eclipse UserFriend
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 09:23 Go to previous messageGo to next message
Eclipse UserFriend
Ok, thanks! Smile
Re: MAP [message #1447594 is a reply to message #1447518] Sat, 18 October 2014 11:20 Go to previous messageGo to next message
Eclipse UserFriend
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 13:10 Go to previous message
Eclipse UserFriend
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: Thu Jul 17 13:30:19 EDT 2025

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

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

Back to the top