X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.datastructures%2Fsrc%2Forg%2Fsimantics%2Futils%2Fdatastructures%2FMapList.java;h=8a28679b747cb860fd6dc1129bfa4c5f0fc627cc;hb=refs%2Fchanges%2F82%2F3982%2F1;hp=cdfa9f7829ddbfb4065d95f9c4ef27cf774e306d;hpb=c4f4133d961fb96ae7a99c86678cb09fb9aff1f5;p=simantics%2Fplatform.git
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 cdfa9f782..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,15 +14,16 @@
*/
package org.simantics.utils.datastructures;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
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.
*
@@ -72,23 +73,12 @@ public class MapList {
protected Map> lists;
public MapList() {
- lists = new HashMap>();
- }
-
- @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 ) {
@@ -109,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;
@@ -260,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()
@@ -271,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);
}
@@ -285,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);
}
}