view artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelData.java @ 9425:3f49835a00c3

Extended CrossSectionFacet so it may fetch different data from within the artifact result. Also allows to have acces to the potentially already computed artifact result via its normal computation cache.
author gernotbelger
date Fri, 17 Aug 2018 15:31:02 +0200
parents ba1e2e8f05d1
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.artifacts.states;

import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.river.artifacts.model.WKms;

import gnu.trove.TDoubleArrayList;

/**
 * Represents a waterlevel fetched with the {@link WaterlevelFetcher}.
 *
 * @author Gernot Belger
 */
public class WaterlevelData {
    private final WKms wkms;

    private final String name;

    private final int year;

    /** If <code>true</code>, tabular export will show gauges for every station, else only for the first gauge */
    private final boolean showAllGauges;

    private final boolean showRefGauges;

    public WaterlevelData(final WKms wkms, final int year, final boolean showAllGauges, final boolean showRefGauges) {
        this(wkms.getName(), wkms, year, showAllGauges, showRefGauges);
    }

    private WaterlevelData(final String name, final WKms wkms, final int year, final boolean showAllGauges, final boolean showRefGauges) {
        this.name = name;
        this.wkms = wkms;
        this.year = year;
        this.showAllGauges = showAllGauges;
        this.showRefGauges = showRefGauges;
    }

    public WaterlevelData filterByRange(final double from, final double to) {
        if (Double.isNaN(from) || Double.isNaN(to)) {
            return this;
        }

        final WKms filteredWkms = this.wkms.filteredKms(from, to);
        return new WaterlevelData(this.name, filteredWkms, this.year, this.showAllGauges, this.showRefGauges);
    }

    public WaterlevelData withName(final String nameToSet) {
        return new WaterlevelData(nameToSet, this.wkms, this.year, this.showAllGauges, this.showRefGauges);
    }

    public String getName() {
        return this.name;
    }

    public WKms getWkms() {
        return this.wkms;
    }

    public boolean isShowAllGauges() {
        return this.showAllGauges;
    }

    public boolean isShowRefGauges() {
        return this.showRefGauges;
    }

    public int getYear() {
        return this.year;
    }

    public boolean covers(final DoubleRange simulationRange) {

        final TDoubleArrayList allKms = this.wkms.allKms();

        if (allKms.isEmpty())
            return false;

        final double min = allKms.min();
        if (min > simulationRange.getMaximumDouble())
            return false;

        final double max = allKms.max();
        if (max < simulationRange.getMinimumDouble())
            return false;

        return true;
    }
}

http://dive4elements.wald.intevation.org