Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/common/AccessHelper.java @ 9067:2ed3824a3d53
sinfo access collision, floodDuration
author | gernotbelger |
---|---|
date | Mon, 14 May 2018 14:59:10 +0200 |
parents | |
children | 1ffd38826175 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AccessHelper.java Mon May 14 14:59:10 2018 +0200 @@ -0,0 +1,108 @@ +/** 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.common; + +import org.apache.log4j.Logger; +import org.dive4elements.artifacts.Artifact; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.Access; + +import gnu.trove.TIntArrayList; + +/** + * @author Domenico Nardi Tironi + * + */ +public class AccessHelper extends Access { + + private static Logger log = Logger.getLogger(AccessHelper.class); + + // private final Artifact artifact; + + public AccessHelper(final Artifact artifact) { + this.artifact = (D4EArtifact) artifact; + } + + public String getYearEpoch() { + + return getString("ye_select"); // ACHTUNG, Ergebniswerte wurden geändert in state.sinfo.epoch und state.sinfo.year + + } + + /** [year1, years2,..] if its about years. */ + public int[] getYears(final String yearSelectedValue) { + int[] years = null; + // if (years != null) { + // return years; + // } + if (getYearEpoch().equals(yearSelectedValue)) { + final TIntArrayList ints = new TIntArrayList(); + final String yearsData = getString("years"); + if (yearsData == null || yearsData.isEmpty()) { + log.warn("No years provided"); + return null; + } + for (final String sValue : yearsData.split(" ")) { + try { + ints.add(Integer.parseInt(sValue)); + } + catch (final NumberFormatException e) { + /* Client should prevent this */ + log.warn("Invalid year value: " + sValue); + continue; + } + } + + if (!ints.isEmpty()) { + ints.sort(); + years = ints.toNativeArray(); + } + return years; + } + return null; + } + + public int[][] getEpochs(final String epochSelectedValue) { + int epochs[][] = null; + // if (epochs != null) { + // return epochs; + // } + + if (!getYearEpoch().equals(epochSelectedValue)) { + return null; + } + + final String data = getString("epochs"); + + if (data == null) { + log.warn("No 'epochs' parameter specified!"); + return null; + } + + final String[] parts = data.split(";"); + + epochs = new int[parts.length][]; + + for (int i = 0; i < parts.length; i++) { + final String[] values = parts[i].split(","); + final TIntArrayList ints = new TIntArrayList(); + try { + ints.add(Integer.parseInt(values[0])); + ints.add(Integer.parseInt(values[1])); + epochs[i] = ints.toNativeArray(); + } + catch (final NumberFormatException nfe) { + log.warn("Cannot parse int from string: '" + values + "'"); + } + } + return epochs; + } + +}