annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/DateUniqueMaker.java @ 8858:a805211690f7 3.2.x

Fix license headers.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:52:41 +0100
parents 2d96d8240e3e
children
rev   line source
8858
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
2 * Software engineering by Intevation GmbH
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
3 *
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
6 * documentation coming with Dive4Elements River for details.
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
7 */
a805211690f7 Fix license headers.
Tom Gottfried <tom@intevation.de>
parents: 6877
diff changeset
8
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
9 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
10
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 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
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 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
14 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
15
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 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
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 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
19 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
20
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 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
22 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
23 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
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
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 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
27
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 // 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
29 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
30 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
31 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
32 }
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 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
34 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
35 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
36 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
37 }
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 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
39 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
40 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
41 // 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
42 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
43 }
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
44 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
45 // 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
46 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
47 }
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
48 }
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
49 }

http://dive4elements.wald.intevation.org