view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents d9dbf0b74bc2
children 2ed3824a3d53
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.flowdepth;

import java.util.Collection;
import java.util.Collections;

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;

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

    private static final String FIELD_DIFFIDS = "diffids";

    private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$

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

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

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

    public boolean isUseTransportBodies() {
        final Boolean useTkh = this.artifact.getDataAsBoolean(FIELD_USE_TKH);
        return useTkh == null ? false : useTkh;
    }

    public Collection<WstSoundingIdPair> getDifferencePairs() {

        final String diffids = getString(FIELD_DIFFIDS);
        if (diffids == null) {
            // Should never happen as this is handled by the ui
            return Collections.emptyList();
        }

        final Collection<WstSoundingIdPair> pairs = WstSoundingIdPair.parsePairs(diffids);
        return pairs;
    }
}

http://dive4elements.wald.intevation.org