Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/common/EpochYearAccessHelper.java @ 9243:da0bdbcd6f09
salix.supraRegional+Regional results
author | gernotbelger |
---|---|
date | Wed, 11 Jul 2018 13:36:18 +0200 |
parents | 2f5052835b76 |
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.common; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.access.Access; import org.dive4elements.river.artifacts.model.DateRange; import org.dive4elements.river.backend.utils.DateUtil; import gnu.trove.TIntArrayList; /** * @author Domenico Nardi Tironi * */ // TODO: rename? public class EpochYearAccessHelper extends Access { private static Logger log = Logger.getLogger(EpochYearAccessHelper.class); // private final Artifact artifact; public EpochYearAccessHelper(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, final String yearKey) { int[] years = null; if (getYearEpoch().equals(yearSelectedValue)) { final TIntArrayList ints = new TIntArrayList(); final String yearsData = getString(yearKey); 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 List<DateRange> getEpochs(final String epochSelectedValue, final String epochKey) { final List<DateRange> epochs = new ArrayList<>(); // if (epochs != null) { // return epochs; // } if (!getYearEpoch().equals(epochSelectedValue)) { return null; } final String data = getString(epochKey); if (data == null) { log.warn("No 'epochs' parameter specified!"); return null; } for (final String part : data.split(";")) { final String[] values = part.split(","); try { epochs.add(new DateRange(DateUtil.getStartDateFromYear(Integer.parseInt(values[0])), DateUtil.getEndDateFromYear(Integer.parseInt(values[1])))); } catch (final NumberFormatException nfe) { log.warn("Cannot parse int from string: '" + values + "'"); } } return epochs; } }