-package org.simantics.graph.store;\r
-\r
-import gnu.trove.list.array.TIntArrayList;\r
-import gnu.trove.map.hash.TIntIntHashMap;\r
-import gnu.trove.map.hash.TIntObjectHashMap;\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.procedure.TIntObjectProcedure;\r
-import gnu.trove.procedure.TIntProcedure;\r
-import gnu.trove.procedure.TObjectIntProcedure;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
-public class IndexMappingUtils {\r
- \r
- public static <T> TIntObjectHashMap<T> map(final TIntIntHashMap map, TIntObjectHashMap<T> target,\r
- final TIntHashSet collisions) {\r
- final TIntObjectHashMap<T> newTarget = new TIntObjectHashMap<T>();\r
- target.forEachEntry(new TIntObjectProcedure<T>() {\r
- @Override\r
- public boolean execute(int a, T b) {\r
- if(map.contains(a))\r
- a = map.get(a);\r
- if(newTarget.put(a, b) != null)\r
- collisions.add(a);\r
- return true;\r
- }\r
- });\r
- return newTarget;\r
- }\r
- \r
- public static void map(TIntIntHashMap map, TIntArrayList target) {\r
- int size = target.size();\r
- for(int i=0;i<size;++i) {\r
- int id = target.getQuick(i);\r
- if(map.contains(id))\r
- target.setQuick(i, map.get(id));\r
- }\r
- } \r
- \r
- public static <T> void map(final TIntIntHashMap map, \r
- final TObjectIntHashMap<T> target) {\r
- target.forEachEntry(new TObjectIntProcedure<T>() {\r
- @Override\r
- public boolean execute(T a, int b) {\r
- if(map.containsKey(b))\r
- target.put(a, map.get(b));\r
- return true;\r
- }\r
- });\r
- }\r
- \r
- public static TIntHashSet map(final TIntIntHashMap map, TIntHashSet target) {\r
- final TIntHashSet newTarget = new TIntHashSet();\r
- target.forEach(new TIntProcedure() {\r
- @Override\r
- public boolean execute(int a) {\r
- if(map.contains(a))\r
- a = map.get(a);\r
- newTarget.add(a);\r
- return true;\r
- }\r
- });\r
- return newTarget;\r
- }\r
-\r
- public static void map(TIntIntHashMap map, int[] target) {\r
- for(int i=0;i<target.length;++i) {\r
- int temp = target[i];\r
- if(map.containsKey(temp))\r
- target[i] = map.get(temp);\r
- }\r
- } \r
-\r
-}\r
+package org.simantics.graph.store;
+
+import gnu.trove.list.array.TIntArrayList;
+import gnu.trove.map.hash.TIntIntHashMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.procedure.TIntObjectProcedure;
+import gnu.trove.procedure.TIntProcedure;
+import gnu.trove.procedure.TObjectIntProcedure;
+import gnu.trove.set.hash.TIntHashSet;
+
+public class IndexMappingUtils {
+
+ public static <T> TIntObjectHashMap<T> map(final TIntIntHashMap map, TIntObjectHashMap<T> target,
+ final TIntHashSet collisions) {
+ final TIntObjectHashMap<T> newTarget = new TIntObjectHashMap<T>();
+ target.forEachEntry(new TIntObjectProcedure<T>() {
+ @Override
+ public boolean execute(int a, T b) {
+ if(map.contains(a))
+ a = map.get(a);
+ if(newTarget.put(a, b) != null)
+ collisions.add(a);
+ return true;
+ }
+ });
+ return newTarget;
+ }
+
+ public static void map(TIntIntHashMap map, TIntArrayList target) {
+ int size = target.size();
+ for(int i=0;i<size;++i) {
+ int id = target.getQuick(i);
+ if(map.contains(id))
+ target.setQuick(i, map.get(id));
+ }
+ }
+
+ public static <T> void map(final TIntIntHashMap map,
+ final TObjectIntHashMap<T> target) {
+ target.forEachEntry(new TObjectIntProcedure<T>() {
+ @Override
+ public boolean execute(T a, int b) {
+ if(map.containsKey(b))
+ target.put(a, map.get(b));
+ return true;
+ }
+ });
+ }
+
+ public static TIntHashSet map(final TIntIntHashMap map, TIntHashSet target) {
+ final TIntHashSet newTarget = new TIntHashSet();
+ target.forEach(new TIntProcedure() {
+ @Override
+ public boolean execute(int a) {
+ if(map.contains(a))
+ a = map.get(a);
+ newTarget.add(a);
+ return true;
+ }
+ });
+ return newTarget;
+ }
+
+ public static void map(TIntIntHashMap map, int[] target) {
+ for(int i=0;i<target.length;++i) {
+ int temp = target[i];
+ if(map.containsKey(temp))
+ target[i] = map.get(temp);
+ }
+ }
+
+}