view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationAccess.java @ 9070:611a523fc42f

VegetationZoneAccessHelper, VegetationTablePanels verbessert
author gernotbelger
date Tue, 15 May 2018 18:04:36 +0200
parents 2ed3824a3d53
children e6b63b2b41b9
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.sinfo.flood_duration;

import org.apache.log4j.Logger;
import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.artifacts.common.EpochYearAccessHelper;
import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode;

import gnu.trove.TDoubleArrayList;

/**
 * Access to the flow depth calculation type specific SInfo artifact data.
 * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent
 * reference to the artifact instance.
 * Hence we do NOT cache any data.
 *
 * @author Gernot Belger
 */
final class FloodDurationAccess extends RangeAccess {

    private static Logger log = Logger.getLogger(FloodDurationAccess.class);

    private final EpochYearAccessHelper helper;

    /// Fields from state:

    // calculation_mode (String), sollte sinfo_calc_flood_duration sein
    // ld_from, ld_to, ld_step
    // riverside, mögliche werte: "state.sinfo.riverside.left" "state.sinfo.riverside.right" "state.sinfo.riverside.both"
    // wspl
    // State.sinfo.WQ:
    // <data name="wq_isq" type="Boolean" />
    // <data name="wq_isfree" type="Boolean" />
    // <data name="wq_isrange" type="Boolean" />
    // <data name="wq_from" type="Double" />
    // <data name="wq_to" type="Double" />
    // <data name="wq_step" type="Double" />
    // <data name="wq_single" type="Double[]" />
    public FloodDurationAccess(final SINFOArtifact artifact) {
        super(artifact);

        /* assert calculation mode */
        final SinfoCalcMode calculationMode = artifact.getCalculationMode();
        this.helper = new EpochYearAccessHelper(artifact);
        assert (calculationMode == SinfoCalcMode.sinfo_calc_flood_duration);
    }

    @Override
    public Double getStep() {
        return super.getStep();
    }

    public String getRiverside() {
        return super.getString("riverside");
    }

    public Boolean getWspl() {
        return super.getBoolean("wspl");
    }

    public Boolean getWqIsQ() {
        if (!getWspl()) {
            return null;//
        }
        return super.getBoolean("wq_isq");
    }

    public Boolean getWqIsFree() {
        if (!getWspl()) {
            return null;//
        }
        return super.getBoolean("wq_isfree");
    }

    public Boolean getWqIsRange() {
        if (!getWspl()) {
            return null;//
        }
        return super.getBoolean("wq_isrange");
    }

    public Double getWqFrom() {
        if (!getWspl()) {
            return null;//
        }
        if (!getWqIsRange())
            return null;

        return super.getDouble("wq_from");
    }

    public Double getWqTo() {
        if (!getWspl()) {
            return null;//
        }
        if (!getWqIsRange())
            return null;
        return super.getDouble("wq_to");
    }

    public Double getWqStep() {
        if (!getWspl()) {
            return null;
        }
        if (!getWqIsRange())
            return null;

        return super.getDouble("wq_step");
    }

    public double[] getWqSingle() {
        if (!getWspl()) {
            return null;//
        }
        if (getWqIsRange())
            return null;

        final String wqSingles = super.getString("wq_single");

        if (wqSingles == null || wqSingles.isEmpty()) {
            log.warn("No wqSingles provided");
            return null;
        }
        final TDoubleArrayList doubles = new gnu.trove.TDoubleArrayList();
        for (final String value : wqSingles.split(" ")) {
            try {

                doubles.add(Double.parseDouble(value));// Punkt/komma?
            }
            catch (final NumberFormatException e) {
                /* Client should prevent this */
                log.warn("Invalid wqsingle value: " + value);
                continue;
            }
        }
        return doubles.toNativeArray();
    }

}

http://dive4elements.wald.intevation.org