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

http://dive4elements.wald.intevation.org