|Re: Do we have any class equivalent to LinkedHashMap in EMF? [message #1004412 is a reply to message #1004175]
||Wed, 23 January 2013 07:25
| Ed Merks
Registered: July 2009
The method for put in org.eclipse.emf.common.util.BasicEMap.put(K, V)
looks like this.
public V put(K key, V value)
int hash = hashOf(key);
if (size > 0)
int index = indexOf(hash);
Entry<K, V> entry = entryForKey(index, hash, key);
if (entry != null)
V result = putEntry(entry, value);
Entry<K, V> entry = newEntry(hash, key, value);
It's clear that a new entry (a put for a key not already in the map) is
added to the end of the list. So the list is not sorted and the order
of that list appears to match exactly your stated needs.
Your general statement about maps doing sorting isn't true either. Only
things like SortedMap do sorting. Most maps maintain an order that's
effectively random based on the hashCodes of the keys and can be
completely reordered by the addition or removal of a key.
I'd be curious to see what test you wrote that confirms sorting but I'll
continue to assert that an EMap is a list and that the iterator
org.eclipse.emf.common.util.BasicEMap.iterator() which is implemented
public Iterator<Map.Entry<K, V>> iterator()
will return you the entries in list order and of course you have
complete control over that order and can even change it using the EMaps
move methods (because an EMap is also an EList).
On 22/01/2013 7:31 PM, Roza Ghamari wrote:
> Hi ED Merks,
> Although an EMap is a list, but maps do not keep the order of
> insertions and they sort based on the Key. I have confirmed it by
> writing a test and the results showed that the map is sorted based on
> the keys (similar to java.util map). I should add that ecore uses
> ECoreEMap class which extends BaseEMap.
Powered by FUDForum
. Page generated in 0.01588 seconds