Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Modeling a HashMap
Modeling a HashMap [message #425404] Mon, 24 November 2008 20:11 Go to next message
Derek Palma is currently offline Derek Palma
Messages: 141
Registered: July 2009
Senior Member
Hi,

I am trying to determine the appropriate pattern for modeling Maps with EMF.
I basically need a Java-like HashMap kind of structure which can be a field
of an EClass (realling nothing fancy, just String keys and values).

What is the best way to model a map? In the EMF book the UML chapter talks
about modeling maps with references to MapEntry classes. However, it seems I
still have to handle the lookup myself. I am presuming others have hit this
before and there is a best practice approach for this. Can someone point me
to some sample models/code for this?

Thanks in advance.
Derek
Re: Modeling a HashMap [message #425419 is a reply to message #425404] Tue, 25 November 2008 16:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050707030306020301070800
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Derek,

Comments below.

Derek Palma wrote:
> Hi,
>
> I am trying to determine the appropriate pattern for modeling Maps
> with EMF. I basically need a Java-like HashMap kind of structure which
> can be a field of an EClass (realling nothing fancy, just String keys
> and values).
>
> What is the best way to model a map? In the EMF book the UML chapter
> talks about modeling maps with references to MapEntry classes.
> However, it seems I still have to handle the lookup myself.
No, EMaps should do the trick: 2.29 How do I create a Map in EMF?
< http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_create_a_ Map_in_EMF.3F>
> I am presuming others have hit this before and there is a best
> practice approach for this. Can someone point me to some sample
> models/code for this?
>
> Thanks in advance.
> Derek

--------------050707030306020301070800
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Derek,<br>
<br>
Comments below.<br>
<br>
Derek Palma wrote:
<blockquote cite="mid:ggfjhl$6k6$1@build.eclipse.org" type="cite">Hi,
<br>
<br>
I am trying to determine the appropriate pattern for modeling Maps with
EMF. I basically need a Java-like HashMap kind of structure which can
be a field of an EClass (realling nothing fancy, just String keys and
values).
<br>
<br>
What is the best way to model a map? In the EMF book the UML chapter
talks about modeling maps with references to MapEntry classes. However,
it seems I still have to handle the lookup myself. </blockquote>
No, EMaps should do the trick: <a
href=" http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_create_a_ Map_in_EMF.3F"><span
class="tocnumber">2.29</span> <span class="toctext">How do I create a
Map in EMF?</span></a>
<blockquote cite="mid:ggfjhl$6k6$1@build.eclipse.org" type="cite">I am
presuming others have hit this before and there is a best practice
approach for this. Can someone point me to some sample models/code for
this?
<br>
<br>
Thanks in advance.
<br>
Derek <br>
</blockquote>
</body>
</html>

--------------050707030306020301070800--
Re: Modeling a HashMap [message #1079625 is a reply to message #425419] Sun, 04 August 2013 18:16 Go to previous messageGo to next message
Edward MacKerrow is currently offline Edward MacKerrow
Messages: 7
Registered: July 2010
Location: Santa Fe, New Mexico
Junior Member
Is there a clean way to sort EMaps by value ? Currently I am creating a TreeMap outside of EMF, creating a Comparator for the values in the TreeMap. Then, after I am done populating the TreeMap, creating an empty EMap and populating it from the sorted by value TreeMap. There is probably a better way to do this directly in EMF ?
Thanks !
Re: Modeling a HashMap [message #1079856 is a reply to message #1079625] Mon, 05 August 2013 02:57 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Edward,

That way is okay. You could also sort in place with
org.eclipse.emf.common.util.ECollections.sort(EList<T>, Comparator<?
super T>) using a comparator that takes the Map.Entry values to induce a
sort order based on the key/value features of the map entry...


On 05/08/2013 12:16 AM, Edward MacKerrow wrote:
> Is there a clean way to sort EMaps by value ? Currently I am creating
> a TreeMap outside of EMF, creating a Comparator for the values in the
> TreeMap. Then, after I am done populating the TreeMap, creating an
> empty EMap and populating it from the sorted by value TreeMap. There
> is probably a better way to do this directly in EMF ?
> Thanks !
Previous Topic:Changing the text color of model Elements
Next Topic:[XCore + Git] Generated .gitignore files in src-gen
Goto Forum:
  


Current Time: Sun Aug 31 02:40:20 EDT 2014

Powered by FUDForum. Page generated in 0.01976 seconds