X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.utils.datastructures%2Fsrc%2Forg%2Fsimantics%2Futils%2Fdatastructures%2FMapList.java;h=8a28679b747cb860fd6dc1129bfa4c5f0fc627cc;hp=900c4b7015dcf6a84b1346939f5902fffffc94e6;hb=0e4c17f6848a62d5f8436233ca3524f8deabee02;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07
diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/MapList.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/MapList.java
index 900c4b701..8a28679b7 100644
--- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/MapList.java
+++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/MapList.java
@@ -14,9 +14,6 @@
*/
package org.simantics.utils.datastructures;
-import gnu.trove.map.hash.THashMap;
-
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -24,6 +21,9 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.eclipse.collections.impl.factory.Lists;
+import org.eclipse.collections.impl.factory.Maps;
+
/**
* MapList is a data structure with map on left side and arraylist on right side.
*
@@ -73,23 +73,12 @@ public class MapList {
protected Map> lists;
public MapList() {
- lists = new THashMap>();
- }
-
- @SuppressWarnings("unchecked")
- public MapList( Class> mapClass ) {
- try {
- lists = (Map>) mapClass.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException( e );
- } catch (IllegalAccessException e) {
- throw new RuntimeException( e );
- }
+ lists = Maps.mutable.empty();
}
public MapList(MapList copyFrom) {
for (Entry> e : copyFrom.lists.entrySet())
- lists.put( e.getKey(), new ArrayList(e.getValue()) );
+ lists.put( e.getKey(), Lists.mutable.withAll(e.getValue()) );
}
public static MapList use( Map> map ) {
@@ -110,20 +99,20 @@ public class MapList {
public void add(L key, int index, R value)
{
- ArrayList list = getOrCreateList(key);
+ List list = getOrCreateList(key);
list.add(index, value);
}
public void addAll(L key, Collection values) {
- ArrayList list = getOrCreateList(key);
+ List list = getOrCreateList(key);
list.addAll(values);
}
- private ArrayList getOrCreateList(L key)
+ private List getOrCreateList(L key)
{
- ArrayList list = (ArrayList) lists.get(key);
+ List list = lists.get(key);
if (list==null) {
- list = new ArrayList(1);
+ list = Lists.mutable.withInitialCapacity(1);
lists.put(key, list);
}
return list;
@@ -261,7 +250,7 @@ public class MapList {
{
List l = lists.get(key);
if (l==null) return Collections.emptyList();
- return new ArrayList(l);
+ return Lists.mutable.withAll(l);
}
public List getAllValuesSnapshot()
@@ -272,7 +261,7 @@ public class MapList {
public List getAllValuesSnapshot(List result)
{
if (result == null)
- result = new ArrayList();
+ result = Lists.mutable.empty();
for (List right : lists.values()) {
result.addAll(right);
}
@@ -286,10 +275,11 @@ public class MapList {
/**
* Makes _this_ maplist immutable.
*/
+ @SuppressWarnings("unchecked")
public void makeImmutable() {
for (Entry> e : lists.entrySet())
- lists.put(e.getKey(), Collections.unmodifiableList(e.getValue()));
- lists = Collections.unmodifiableMap(lists);
+ lists.put(e.getKey(), (List) Lists.immutable.withAll(e.getValue()));
+ lists = (Map>) Maps.immutable.withAll(lists);
}
}