view artifacts/src/main/java/org/dive4elements/river/utils/GaugeIndex.java @ 9415:9744ce3c3853

Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets. The facets also put the valid station range into their xml-metadata
author gernotbelger
date Thu, 16 Aug 2018 16:27:53 +0200
parents 385b52ccde23
children
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * 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)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.utils;

import java.util.List;

import org.dive4elements.river.model.Gauge;

/**
 * Allows performant access to gauges by station.
 * @author Gernot Belger
 */
public class GaugeIndex {
    private final List<Gauge> gauges;

    private Gauge lastGauge = null;

    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(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;
    }
}

http://dive4elements.wald.intevation.org