view artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java @ 9132:8cc192731c7d

WQSelect can now handle distance-only data
author gernotbelger
date Wed, 06 Jun 2018 14:24:51 +0200
parents e3519c3e7a0a
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.access;

import org.dive4elements.artifactdatabase.data.StateData;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.states.ComputationRangeState;
import org.dive4elements.river.utils.DoubleUtil;

/**
 * Access to data handled by {@link ComputationRangeState}.
 *
 * @author Gernot Belger
 */
public class ComputationRangeAccess extends RangeAccess {

    public ComputationRangeAccess(final D4EArtifact artifact) {
        super(artifact);
    }

    public double[] getFromToStep() {

        if (!isRange())
            return null;

        final double[] fromTo = getKmRange();

        if (fromTo == null)
            return null;

        final StateData dStep = getArtifact().getData("ld_step");
        if (dStep == null)
            return null;

        final double[] result = new double[3];
        result[0] = fromTo[0];
        result[1] = fromTo[1];

        try {
            final String dStepValue = (String) dStep.getValue();
            result[2] = DoubleUtil.round(Double.parseDouble(dStepValue) / 1000d);
            return result;
        }
        catch (final NumberFormatException nfe) {
            nfe.printStackTrace();
            return null;
        }
    }

    public final double getStartKm() {

        final KM_MODE mode = getKmRangeMode();
        switch (mode) {
        case RANGE:
        case DISTANCE_ONLY:
            return getFrom();

        case LOCATIONS:
        case NONE:
        default:
            final double[] locations = getLocations();
            if( locations != null && locations.length > 0 )
                // TODO: this is the old behaviour, but what happens if the user enters the values unsorted?
                return locations[0];

            return Double.NaN;
        }
    }

    public double[] getKms() {

        if (isRange())
            return getKmSteps();

        return getLocations();
    }
}

http://dive4elements.wald.intevation.org