comparison 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
comparison
equal deleted inserted replaced
6889:feaf76b70190 6891:8efef772a488
10 10
11 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
12 import org.dive4elements.river.artifacts.model.Parameters; 12 import org.dive4elements.river.artifacts.model.Parameters;
13 13
14 import org.dive4elements.river.utils.KMIndex; 14 import org.dive4elements.river.utils.KMIndex;
15
16 import gnu.trove.TIntIntHashMap;
17 15
18 import java.io.Serializable; 16 import java.io.Serializable;
19 import java.util.Collection; 17 import java.util.Collection;
20 import java.util.Date; 18 import java.util.Date;
21 import java.util.TreeMap; 19 import java.util.TreeMap;
70 } 68 }
71 return dates.values(); 69 return dates.values();
72 } 70 }
73 71
74 public void remapReferenceIndicesToRank() { 72 public void remapReferenceIndicesToRank() {
75 Collection<Integer> referenceIndices = getReferenceEventsIndices(); 73 RankRemapper remapper = new RankRemapper();
76 int index = 0; 74 for (Integer idx: getReferenceEventsIndices()) {
77 TIntIntHashMap map = new TIntIntHashMap(); 75 remapper.toMap(idx);
78 boolean debug = log.isDebugEnabled();
79 for (Integer refId: referenceIndices) {
80 if (debug) {
81 log.debug("map " + refId + " -> " + index);
82 }
83 map.put(refId, index);
84 ++index;
85 } 76 }
86
87 // Two passes: If there are shared references do not
88 // remap them twice. In the first pass all indices are
89 // mapped to negative values (assuming the original data
90 // is all positive). If a negative value is found ignore
91 // it because it was remapped before.
92
93 for (KMIndex.Entry<QWD []> entry: referenced) { 77 for (KMIndex.Entry<QWD []> entry: referenced) {
94 for (QWD value: entry.getValue()) { 78 for (QWD value: entry.getValue()) {
95 if (value.index >= 0) { 79 remapper.remap(value);
96 if (map.containsKey(value.index)) {
97 value.index = -(map.get(value.index) + 1);
98 }
99 else {
100 log.warn("Could not remap index: " + value.index);
101 }
102 }
103 }
104 }
105
106 // In the second pass all indices are turned to positive
107 // values again.
108 for (KMIndex.Entry<QWD []> entry: referenced) {
109 for (QWD value: entry.getValue()) {
110 if (value.index < 0) {
111 value.index = -(value.index + 1);
112 }
113 } 80 }
114 } 81 }
115 } 82 }
116 83
117 public Collection<Date> getReferenceEventsDates() { 84 public Collection<Date> getReferenceEventsDates() {

http://dive4elements.wald.intevation.org