Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/utils/GaugeIndex.java @ 9295:385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
author | mschaefer |
---|---|
date | Tue, 24 Jul 2018 18:51:47 +0200 |
parents | 6823991e1ed1 |
children |
rev | line source |
---|---|
8850 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
9295
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
2 * Software engineering by |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
8850 | 4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.utils; | |
11 | |
12 import java.util.List; | |
13 | |
14 import org.dive4elements.river.model.Gauge; | |
15 | |
16 /** | |
17 * Allows performant access to gauges by station. | |
18 * @author Gernot Belger | |
19 */ | |
20 public class GaugeIndex { | |
9295
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
21 private final List<Gauge> gauges; |
8850 | 22 |
9295
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
23 private Gauge lastGauge = null; |
8850 | 24 |
9295
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
25 public GaugeIndex(final List<Gauge> gauges) { |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
26 this.gauges = gauges; |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
27 } |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
28 |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
29 public Gauge findGauge(final double km) { |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
30 |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
31 // REMARK: this is code copied from WaterlevelExporter, which is honestly not very fast/good. |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
32 // Instead we need to index by range with an RTree and directly acccess the right gauge. |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
33 |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
34 if( this.lastGauge != null && this.lastGauge.getRange().contains(km) ) |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
35 return this.lastGauge; |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
36 |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
37 final Gauge gauge = findGauge(km, this.gauges); |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
38 |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
39 this.lastGauge = gauge; |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
40 |
8850 | 41 return gauge; |
9295
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
42 } |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
43 |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
44 private static Gauge findGauge(final double km, final List<Gauge> gauges) { |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
45 for (final Gauge gauge: gauges) { |
8850 | 46 if (gauge.getRange().contains(km)) { |
47 return gauge; | |
48 } | |
49 } | |
50 return null; | |
51 } | |
9295
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
52 |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
53 public List<Gauge> getGauges() { |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
54 return this.gauges; |
385b52ccde23
Work on U-Info salix line calculation and chart (no scenario case)
mschaefer
parents:
8850
diff
changeset
|
55 } |
8850 | 56 } |