Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
6876:a071f0a80883 | 6877:2d96d8240e3e |
---|---|
1 package org.dive4elements.river.artifacts.model.fixings; | |
2 | |
3 import java.util.Date; | |
4 | |
5 import gnu.trove.TIntObjectHashMap; | |
6 import gnu.trove.TLongHashSet; | |
7 | |
8 public class DateUniqueMaker { | |
9 | |
10 private TLongHashSet times; | |
11 private TIntObjectHashMap already; | |
12 | |
13 public DateUniqueMaker() { | |
14 times = new TLongHashSet(); | |
15 already = new TIntObjectHashMap(); | |
16 } | |
17 | |
18 public <T extends QWI> void makeUnique(T t) { | |
19 | |
20 // Map same index to same new value | |
21 if (already.containsKey(t.index)) { | |
22 t.date = (Date)already.get(t.index); | |
23 return; | |
24 } | |
25 long time = t.date.getTime(); | |
26 if (!times.add(time)) { // same found before | |
27 do { | |
28 time += 30L*1000L; // Add 30secs | |
29 } | |
30 while (!times.add(time)); | |
31 Date newDate = new Date(time); | |
32 already.put(t.index, newDate); | |
33 // Write back modified time. | |
34 t.date = newDate; | |
35 } | |
36 else { | |
37 // register as seen. | |
38 already.put(t.index, t.date); | |
39 } | |
40 } | |
41 } |