view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentAccess.java @ 8951:322b0e6298ea

Work on SINFO FlowDepth-Development
author gernotbelger
date Fri, 16 Mar 2018 18:08:38 +0100
parents
children 611a523fc42f
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.flowdepthdev;

import java.util.List;

import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode;
import org.dive4elements.river.artifacts.sinfo.flowdepth.WstSoundingIdPair;

/**
 * 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 FlowDepthDevelopmentAccess extends RangeAccess {

    static final String FIELD_DIFFID_CURRENT = "diffid_current";
    static final String FIELD_DIFFID_HIST = "diffid_historical";

    public FlowDepthDevelopmentAccess(final SINFOArtifact artifact) {
        super(artifact);

        /* assert calculation mode */
        final SinfoCalcMode calculationMode = artifact.getCalculationMode();
        assert (calculationMode == SinfoCalcMode.sinfo_calc_flow_depth_minmax);
    }

    public DoubleRange getRange() {
        final double from = getFrom();
        final double to = getTo();
        return new DoubleRange(from, to);
    }

    public WstSoundingIdPair getCurrentPair() {
        return getPair(FIELD_DIFFID_CURRENT);
    }

    public WstSoundingIdPair getHistoricalPair() {
        return getPair(FIELD_DIFFID_HIST);
    }

    private WstSoundingIdPair getPair(final String field) {
        final String diffids = getString(field);

        /* fetch the raw configured pairs */
        final List<WstSoundingIdPair> diffPairs = WstSoundingIdPair.parsePairs(diffids);

        if (diffPairs.size() != 1)
            return null;

        return diffPairs.get(0);
    }
}

http://dive4elements.wald.intevation.org