teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.access; rrenkert@4371: rrenkert@4371: import gnu.trove.TIntArrayList; rrenkert@4371: rrenkert@4371: import org.apache.log4j.Logger; rrenkert@4371: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; rrenkert@4371: rrenkert@4371: rrenkert@4371: public class SedimentLoadAccess felix@4826: extends RangeAccess rrenkert@4371: { tom@8856: private static final Logger log = Logger.getLogger( tom@8856: SedimentLoadAccess.class); rrenkert@4371: rrenkert@4371: private String time; rrenkert@4371: private String unit; rrenkert@4371: teichmann@8051: private int [][] epochs; teichmann@8051: andre@8532: private int [] years; teichmann@8051: andre@8239: private Integer sqTiId; andre@8236: teichmann@6101: public SedimentLoadAccess(D4EArtifact artifact) { teichmann@6101: super(artifact); andre@8532: years = null; rrenkert@4371: } rrenkert@4371: rrenkert@4371: public Double getLowerKM() { felix@4826: // TODO update callers felix@4826: return getFrom(); rrenkert@4371: } rrenkert@4371: rrenkert@4371: public Double getUpperKM() { felix@4826: // TODO update callers felix@4826: return getTo(); rrenkert@4371: } rrenkert@4371: rrenkert@4371: public String getYearEpoch() { rrenkert@4371: if (time == null) { rrenkert@4371: time = getString("ye_select"); rrenkert@4371: } rrenkert@4371: return time; rrenkert@4371: } rrenkert@4371: andre@8532: /** [year1, years2,..] if its about years. */ andre@8532: public int[] getYears() { andre@8532: if (years != null) { andre@8532: return years; teichmann@8051: } rrenkert@4371: if (getYearEpoch().equals("year") ) { andre@8532: TIntArrayList ints = new TIntArrayList(); andre@8532: String yearsData = getString("years"); andre@8532: if (yearsData == null || yearsData.isEmpty()) { andre@8532: log.warn("No years provided"); rrenkert@4371: return null; rrenkert@4371: } andre@8532: for (String sValue :yearsData.split(" ")) { andre@8532: try { andre@8532: ints.add(Integer.parseInt(sValue)); andre@8532: } catch (NumberFormatException e) { andre@8532: /* Client should prevent this */ andre@8532: log.warn("Invalid year value: " + sValue); andre@8532: continue; andre@8532: } andre@8532: } rrenkert@4371: andre@8532: if (!ints.isEmpty()) { andre@8532: ints.sort(); andre@8532: years = ints.toNativeArray(); andre@8532: } andre@8532: return years; rrenkert@4371: } rrenkert@4371: return null; rrenkert@4371: } rrenkert@4371: rrenkert@4371: public int[][] getEpochs() { teichmann@8051: teichmann@8051: if (epochs != null) { teichmann@8051: return epochs; teichmann@8051: } teichmann@8051: felix@7530: if (!getYearEpoch().equals("epoch") && felix@7530: !getYearEpoch().equals("off_epoch")) { felix@7530: return null; rrenkert@4371: } rrenkert@4371: felix@7530: String data = getString("epochs"); felix@7530: felix@7530: if (data == null) { teichmann@8202: log.warn("No 'epochs' parameter specified!"); felix@7530: return null; felix@7530: } felix@7530: felix@7530: String[] parts = data.split(";"); felix@7530: teichmann@8051: epochs = new int[parts.length][]; felix@7530: felix@7530: for (int i = 0; i < parts.length; i++) { felix@7530: String[] values = parts[i].split(","); felix@7530: TIntArrayList ints = new TIntArrayList(); felix@7530: try { felix@7530: ints.add(Integer.parseInt(values[0])); felix@7530: ints.add(Integer.parseInt(values[1])); teichmann@8051: epochs[i] = ints.toNativeArray(); felix@7530: } felix@7530: catch (NumberFormatException nfe) { teichmann@8202: log.warn("Cannot parse int from string: '" + values + "'"); felix@7530: } felix@7530: } teichmann@8051: return epochs; rrenkert@4371: } rrenkert@4371: felix@6677: /** Returns the selected unit (t/a or m3/a). */ rrenkert@4371: public String getUnit () { rrenkert@4371: if (unit == null) { rrenkert@4371: unit = getString("unit"); rrenkert@4371: } rrenkert@4371: return unit; rrenkert@4371: } andre@8236: andre@8236: /** Returns the selected time interval id */ andre@8239: public Integer getSQTiId () { andre@8239: if (sqTiId == null) { andre@8239: sqTiId = getInteger("sq_ti_id"); andre@8236: } andre@8236: return sqTiId; andre@8236: } andre@8236: rrenkert@4371: } rrenkert@4371: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :