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; felix@4825: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; sascha@3776: teichmann@5831: import org.dive4elements.river.artifacts.model.RangeWithValues; teichmann@5831: teichmann@5831: import org.dive4elements.river.utils.DoubleUtil; sascha@3776: sascha@3776: import java.util.ArrayList; sascha@3776: import java.util.List; sascha@3776: sascha@3775: import org.apache.log4j.Logger; sascha@3775: felix@4040: /** Access data used for extreme value analysis. */ sascha@3775: public class ExtremeAccess felix@4825: extends RangeAccess sascha@3775: { teichmann@8202: /** Our private log. */ teichmann@8202: private static Logger log = Logger.getLogger(ExtremeAccess.class); sascha@3775: sascha@3776: protected Long start; sascha@3776: protected Long end; sascha@3776: sascha@3776: protected Double percent; sascha@3776: sascha@3776: protected String function; sascha@3776: sascha@3776: protected List ranges; sascha@3776: felix@4052: teichmann@6101: public ExtremeAccess(D4EArtifact artifact) { teichmann@6101: super(artifact); sascha@3776: } sascha@3776: felix@4332: felix@4332: /** Returns the percent given. */ sascha@3776: public Double getPercent() { sascha@3776: sascha@3776: if (percent == null) { sascha@3776: percent = getDouble("percent"); sascha@3776: } sascha@3776: teichmann@8202: if (log.isDebugEnabled()) { teichmann@8202: log.debug("percent: '" + percent + "'"); sascha@3776: } sascha@3776: sascha@3776: return percent; sascha@3776: } sascha@3776: sascha@3776: public String getFunction() { sascha@3776: if (function == null) { sascha@3776: function = getString("function"); sascha@3776: } sascha@3776: teichmann@8202: if (log.isDebugEnabled()) { teichmann@8202: log.debug("function: '" + function + "'"); sascha@3776: } sascha@3776: sascha@3776: return function; sascha@3776: } sascha@3776: felix@4333: felix@4333: /** Find first RangeWithValues for which the given location felix@4333: * is within the range and return its values. felix@4333: * @return values of first suitable rangewithvalues or null. felix@4333: */ felix@4333: public double[] getValuesForRange(double location) { teichmann@8202: log.debug("ExtemeAcces.getValuesForRange"); felix@4333: for (RangeWithValues rangeValues: getRanges()) { felix@4333: if (rangeValues.inside(location)) { felix@4333: return rangeValues.getValues(); felix@4333: } felix@4333: } felix@4333: return null; felix@4333: } felix@4333: felix@4333: sascha@3776: public List getRanges() { sascha@3776: sascha@3776: if (ranges == null) { sascha@3776: String rangesS = getString("ranges"); felix@4272: if (rangesS == null) { sascha@3776: return null; sascha@3776: } sascha@3776: ranges = new ArrayList(); tom@8856: DoubleUtil.parseSegments( tom@8856: rangesS, tom@8856: new DoubleUtil.SegmentCallback() { tom@8856: @Override tom@8856: public void newSegment( tom@8856: double from, tom@8856: double to, tom@8856: double [] values tom@8856: ) { tom@8856: ranges.add(new RangeWithValues(from, to, values)); tom@8856: } tom@8856: }); sascha@3776: } sascha@3776: teichmann@8202: if (log.isDebugEnabled()) { teichmann@8202: log.debug("ranges: " + ranges); sascha@3776: } sascha@3776: sascha@3776: return ranges; sascha@3776: } sascha@3775: } sascha@3775: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :