diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixResult.java @ 6891:8efef772a488

FixA: Remapped indices of analysis periods, too. Needs testing!
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 21 Aug 2013 15:41:58 +0200
parents 2d96d8240e3e
children a3f318347707 0a5239a1e46e
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixResult.java	Wed Aug 21 15:00:40 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixResult.java	Wed Aug 21 15:41:58 2013 +0200
@@ -13,8 +13,6 @@
 
 import org.dive4elements.river.utils.KMIndex;
 
-import gnu.trove.TIntIntHashMap;
-
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.Date;
@@ -72,44 +70,13 @@
     }
 
     public void remapReferenceIndicesToRank() {
-        Collection<Integer> referenceIndices = getReferenceEventsIndices();
-        int index = 0;
-        TIntIntHashMap map = new TIntIntHashMap();
-        boolean debug = log.isDebugEnabled();
-        for (Integer refId: referenceIndices) {
-            if (debug) {
-                log.debug("map " + refId + " -> " + index);
-            }
-            map.put(refId, index);
-            ++index;
+        RankRemapper remapper = new RankRemapper();
+        for (Integer idx: getReferenceEventsIndices()) {
+            remapper.toMap(idx);
         }
-
-        // Two passes: If there are shared references do not
-        // remap them twice. In the first pass all indices are
-        // mapped to negative values (assuming the original data
-        // is all positive). If a negative value is found ignore
-        // it because it was remapped before.
-
         for (KMIndex.Entry<QWD []> entry: referenced) {
             for (QWD value: entry.getValue()) {
-                if (value.index >= 0) {
-                    if (map.containsKey(value.index)) {
-                        value.index = -(map.get(value.index) + 1);
-                    }
-                    else {
-                        log.warn("Could not remap index: " + value.index);
-                    }
-                }
-            }
-        }
-
-        // In the second pass all indices are turned to positive
-        // values again.
-        for (KMIndex.Entry<QWD []> entry: referenced) {
-            for (QWD value: entry.getValue()) {
-                if (value.index < 0) {
-                    value.index = -(value.index + 1);
-                }
+                remapper.remap(value);
             }
         }
     }

http://dive4elements.wald.intevation.org