annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/RankRemapper.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
children 0a5239a1e46e
rev   line source
6891
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 *
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 */
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 package org.dive4elements.river.artifacts.model.fixings;
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 import java.util.IdentityHashMap;
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 import gnu.trove.TIntIntHashMap;
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 public class RankRemapper {
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 private static Logger log = Logger.getLogger(RankRemapper.class);
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 private TIntIntHashMap index2rank;
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 private IdentityHashMap<QWI, Boolean> visited;
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 public RankRemapper() {
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 index2rank = new TIntIntHashMap();
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 visited = new IdentityHashMap<QWI, Boolean>();
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 }
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 public void toMap(int index) {
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 index2rank.put(index, index2rank.size());
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 }
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 public <I extends QWI> void remap(I qwi) {
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 if (!visited.containsKey(qwi)) {
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 int idx = qwi.index;
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36 if (index2rank.containsKey(idx)) {
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 qwi.index = index2rank.get(idx);
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 } else if (log.isDebugEnabled()) {
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39 log.debug("Cannot remap " + idx);
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
40 }
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41 visited.put(qwi, true);
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 }
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 }
8efef772a488 FixA: Remapped indices of analysis periods, too. Needs testing!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 }

http://dive4elements.wald.intevation.org