Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/utils/GaugeIndex.java Tue Jul 24 16:55:43 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/GaugeIndex.java Tue Jul 24 18:51:47 2018 +0200 @@ -1,6 +1,6 @@ /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde - * Software engineering by - * Björnsen Beratende Ingenieure GmbH + * Software engineering by + * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) @@ -18,35 +18,39 @@ * @author Gernot Belger */ public class GaugeIndex { - private List<Gauge> gauges; - - private Gauge lastGauge = null; - - public GaugeIndex( List<Gauge> gauges) { - this.gauges = gauges; - } - - public Gauge findGauge(double km) { + private final List<Gauge> gauges; - // REMARK: this is code copied from WaterlevelExporter, which is honestly not very fast/good. - // Instead we need to index by range with an RTree and directly acccess the right gauge. - - if( lastGauge != null && lastGauge.getRange().contains(km) ) - return lastGauge; - - final Gauge gauge = findGauge(km, gauges); + private Gauge lastGauge = null; - lastGauge = gauge; - + public GaugeIndex(final List<Gauge> gauges) { + this.gauges = gauges; + } + + public Gauge findGauge(final double km) { + + // REMARK: this is code copied from WaterlevelExporter, which is honestly not very fast/good. + // Instead we need to index by range with an RTree and directly acccess the right gauge. + + if( this.lastGauge != null && this.lastGauge.getRange().contains(km) ) + return this.lastGauge; + + final Gauge gauge = findGauge(km, this.gauges); + + this.lastGauge = gauge; + return gauge; - } - - private static Gauge findGauge(double km, List<Gauge> gauges) { - for (Gauge gauge: gauges) { + } + + private static Gauge findGauge(final double km, final List<Gauge> gauges) { + for (final Gauge gauge: gauges) { if (gauge.getRange().contains(km)) { return gauge; } } return null; } + + public List<Gauge> getGauges() { + return this.gauges; + } } \ No newline at end of file