view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java @ 8915:d9dbf0b74bc2

Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
author gernotbelger
date Wed, 28 Feb 2018 17:27:15 +0100
parents 7bbfb24e6eec
children 5d5d482da3e9
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.ArrayList;
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;
import org.dive4elements.river.backend.utils.StringUtil;

/**
 * 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 {
    public static class DifferencesPair {
        private final String wstId;
        private final String soundingId;

        public DifferencesPair(final String wstId, final String soundingId) {
            this.wstId = wstId;
            this.soundingId = soundingId;
        }

        public String getWstId() {
            return this.wstId;
        }

        public String getSoundingId() {
            return this.soundingId;
        }
    }

    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<DifferencesPair> getDifferencePairs() {

        final Collection<DifferencesPair> diffPairs = new ArrayList<>();

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

        // FIXME: this way of parsing the datacage-ids is repeated all over flys!
        final String datas[] = diffids.split("#");
        for (int i = 0; i < datas.length; i += 2) {
            final String leftId = StringUtil.unbracket(datas[i]);
            final String rightId = StringUtil.unbracket(datas[i + 1]);

            diffPairs.add(new DifferencesPair(leftId, rightId));
        }

        return Collections.unmodifiableCollection(diffPairs);
    }
}

http://dive4elements.wald.intevation.org