view artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationzonesAccess.java @ 9069:1ffd38826175

access uinfo.vegetationzones+inundation_duration
author gernotbelger
date Tue, 15 May 2018 12:00:26 +0200
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.uinfo.vegetationzones;

import java.util.ArrayList;

import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.artifacts.common.AccessHelper;
import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
import org.dive4elements.river.artifacts.uinfo.UinfoCalcMode;

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

    // IMMER ABGLEICHEN MIT SuperVegZonesTablePanel.TABLE_CELL_SEPARATOR
    public static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
    public static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
    private final AccessHelper helper;

    // Fields from state:
    // calculation_mode (String)
    // ld_from, ld_to,ld_step
    // vegzones (String)

    public VegetationzonesAccess(final UINFOArtifact uinfo) {
        super(uinfo);

        /* assert calculation mode */
        final UinfoCalcMode calculationMode = uinfo.getCalculationMode();
        this.helper = new AccessHelper(uinfo);
        assert (calculationMode == UinfoCalcMode.uinfo_vegetation_zones);
    }

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

    public ArrayList<String[]> getVegZones() {
        final ArrayList<String[]> results = new ArrayList<>();
        final String zonesRaw = super.getString("vegzones");
        if (zonesRaw.contains(TABLE_ROW_SEPARATOR)) {
            final String[] rows = zonesRaw.split(TABLE_ROW_SEPARATOR);
            for (final String row : rows) {
                if (row.contains(TABLE_CELL_SEPARATOR)) {
                    final String[] result = row.split(TABLE_CELL_SEPARATOR);
                    results.add(result);
                }
            }
        }
        return results;
    }

}

http://dive4elements.wald.intevation.org