Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java Tue May 15 12:00:26 2018 +0200 @@ -0,0 +1,102 @@ +/* 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.inundationduration; + +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 InundationDurationAccess 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 + // ye_select (String; state.uinfo.totalepoch oder state.uinfo.year) + // singleyear (String) + // totalepoch (String; TODO: minmax totalEpoch herausfinden und setzen (nicht hier.. aber trotzdem die Erinnerung hier)) + // use_scenario boolean (danach kommt kein radioBtn, sondern sedimentheight-Eingabe) + // sedimentheight String + // + // vegzones (String) TODO: MIT VegetationzonesAccess zusammenlegen + + public InundationDurationAccess(final UINFOArtifact uinfo) { + super(uinfo); + + /* assert calculation mode */ + final UinfoCalcMode calculationMode = uinfo.getCalculationMode(); + this.helper = new AccessHelper(uinfo); + assert (calculationMode == UinfoCalcMode.uinfo_inundation_duration); + } + + public DoubleRange getRange() { + final double from = getFrom(); + final double to = getTo(); + return new DoubleRange(from, to); + } + + public Double getSedimentHeight() { + if (super.getBoolean("use_scenario")) { + return super.getDouble("sedimentheight"); // TODO: INPUT Valdiation (nicht hier, sondern im Panel. Erinnerung) + } + return null; + } + + public Integer getYear() { + final int[] years = this.helper.getYears("state.uinfo.year", "singleyear"); + if (years != null) { + return years[0]; + } + return null; + } + + public int[] getTotalEpoch() { + final int[][] epochs = this.helper.getEpochs("state.uinfo.totalepoch", "totalepoch"); + if (epochs != null) { + return epochs[0]; + } + return null; + } + + public ArrayList<String[]> getVegZones() { + // TODO: MIT VegetationzonesAccess zusammenlegen + 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; + } + +} \ No newline at end of file