Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/DateUniqueMaker.java @ 6877:2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 21 Aug 2013 01:09:25 +0200 |
parents | |
children | a805211690f7 |
rev | line source |
---|---|
6877
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 package org.dive4elements.river.artifacts.model.fixings; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.Date; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 import gnu.trove.TIntObjectHashMap; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 import gnu.trove.TLongHashSet; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 public class DateUniqueMaker { |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 private TLongHashSet times; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 private TIntObjectHashMap already; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
12 |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
13 public DateUniqueMaker() { |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 times = new TLongHashSet(); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 already = new TIntObjectHashMap(); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 } |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 public <T extends QWI> void makeUnique(T t) { |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 // Map same index to same new value |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 if (already.containsKey(t.index)) { |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
22 t.date = (Date)already.get(t.index); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 return; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
24 } |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 long time = t.date.getTime(); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 if (!times.add(time)) { // same found before |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
27 do { |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
28 time += 30L*1000L; // Add 30secs |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
29 } |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 while (!times.add(time)); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 Date newDate = new Date(time); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
32 already.put(t.index, newDate); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 // Write back modified time. |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 t.date = newDate; |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 else { |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 // register as seen. |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
38 already.put(t.index, t.date); |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
2d96d8240e3e
FixA: Make dates of analysis periods unique, too. TODO: Remap the indices like the reference interval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
41 } |