*/
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.
* <p>
protected Map<L, List<R>> lists;
public MapList() {
- lists = new HashMap<L, List<R>>();
- }
-
- @SuppressWarnings("unchecked")
- public MapList( Class<?> mapClass ) {
- try {
- lists = (Map<L, List<R>>) mapClass.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException( e );
- } catch (IllegalAccessException e) {
- throw new RuntimeException( e );
- }
+ lists = Maps.mutable.empty();
}
public MapList(MapList<L, R> copyFrom) {
for (Entry<L, List<R>> e : copyFrom.lists.entrySet())
- lists.put( e.getKey(), new ArrayList<R>(e.getValue()) );
+ lists.put( e.getKey(), Lists.mutable.withAll(e.getValue()) );
}
public static <L, R> MapList<L, R> use( Map<L, List<R>> map ) {
public void add(L key, int index, R value)
{
- ArrayList<R> list = getOrCreateList(key);
+ List<R> list = getOrCreateList(key);
list.add(index, value);
}
public void addAll(L key, Collection<R> values) {
- ArrayList<R> list = getOrCreateList(key);
+ List<R> list = getOrCreateList(key);
list.addAll(values);
}
- private ArrayList<R> getOrCreateList(L key)
+ private List<R> getOrCreateList(L key)
{
- ArrayList<R> list = (ArrayList<R>) lists.get(key);
+ List<R> list = lists.get(key);
if (list==null) {
- list = new ArrayList<R>(1);
+ list = Lists.mutable.withInitialCapacity(1);
lists.put(key, list);
}
return list;
{
List<R> l = lists.get(key);
if (l==null) return Collections.emptyList();
- return new ArrayList<R>(l);
+ return Lists.mutable.withAll(l);
}
public List<R> getAllValuesSnapshot()
public List<R> getAllValuesSnapshot(List<R> result)
{
if (result == null)
- result = new ArrayList<R>();
+ result = Lists.mutable.empty();
for (List<R> right : lists.values()) {
result.addAll(right);
}
/**
* Makes _this_ maplist immutable.
*/
+ @SuppressWarnings("unchecked")
public void makeImmutable() {
for (Entry<L, List<R>> e : lists.entrySet())
- lists.put(e.getKey(), Collections.unmodifiableList(e.getValue()));
- lists = Collections.unmodifiableMap(lists);
+ lists.put(e.getKey(), (List<R>) Lists.immutable.withAll(e.getValue()));
+ lists = (Map<L, List<R>>) Maps.immutable.withAll(lists);
}
}
*/
package org.simantics.utils.datastructures.hints;
-import gnu.trove.map.hash.THashMap;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.collections.impl.factory.Maps;
/**
*
*/
public class HintContext extends AbstractHintObservable implements IHintContext, Cloneable {
- protected Map<Key, Object> hints = new THashMap<Key, Object>();
+ protected Map<Key, Object> hints = Maps.mutable.empty();
@Override
public void clearWithoutNotification() {