teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5863: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5863: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.access; teichmann@4812: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@4812: teichmann@5831: import org.dive4elements.river.artifacts.model.Segment; teichmann@4812: teichmann@4812: import java.util.Collections; teichmann@4812: import java.util.List; teichmann@4812: teichmann@4812: import org.apache.log4j.Logger; teichmann@4812: teichmann@5831: import org.dive4elements.river.utils.DoubleUtil; teichmann@4812: teichmann@4812: public class Calculation4Access felix@4857: extends RangeAccess teichmann@4812: { teichmann@4812: private static Logger log = Logger.getLogger(Calculation4Access.class); teichmann@4812: teichmann@4812: protected List segments; teichmann@4812: teichmann@4812: protected double [] fromToStep; teichmann@4812: teichmann@4812: protected Boolean isQ; teichmann@4812: teichmann@4812: protected Boolean isRange; teichmann@4812: teichmann@4812: teichmann@5867: public Calculation4Access(D4EArtifact artifact) { felix@4857: super(artifact, null); teichmann@4812: } teichmann@4812: teichmann@4812: public List getSegments() { teichmann@4812: if (segments == null) { teichmann@4812: String input = getString("wq_values"); teichmann@4812: if (input == null || (input = input.trim()).length() == 0) { teichmann@4812: log.warn("no wq_values given"); teichmann@4812: segments = Collections.emptyList(); teichmann@4812: } teichmann@4839: else { teichmann@4839: segments = Segment.parseSegments(input); teichmann@4839: } teichmann@4812: } teichmann@4812: return segments; teichmann@4812: } teichmann@4812: teichmann@4812: public boolean isQ() { teichmann@4812: if (isQ == null) { teichmann@4812: Boolean value = getBoolean("wq_isq"); teichmann@4812: isQ = value != null && value; teichmann@4812: } teichmann@4812: return isQ; teichmann@4812: } teichmann@4812: teichmann@4812: public boolean isRange() { teichmann@4812: if (isRange == null) { teichmann@4812: String mode = getString("ld_mode"); teichmann@4812: isRange = mode == null || mode.equals("distance"); teichmann@4812: } teichmann@4812: return isRange; teichmann@4812: } teichmann@4812: teichmann@4812: public double [] getFromToStep() { teichmann@4812: if (fromToStep == null) { teichmann@4812: // XXX: Is this really needed in this calculation? teichmann@4812: if (!isRange()) { teichmann@4812: return null; teichmann@4812: } teichmann@4812: teichmann@5867: // XXX: D4EArtifact sucks! felix@4857: // TODO further use RangeAccess functionality. felix@4857: double [] fromTo = getKmRange(); teichmann@4812: teichmann@4812: if (fromTo == null) { teichmann@4812: return null; teichmann@4812: } teichmann@4812: teichmann@4812: Double dStep = getDouble("ld_step"); teichmann@4812: if (dStep == null) { teichmann@4812: return null; teichmann@4812: } teichmann@4812: teichmann@4812: fromToStep = new double [] { teichmann@4812: fromTo[0], teichmann@4812: fromTo[1], teichmann@4812: DoubleUtil.round(dStep / 1000d) teichmann@4812: }; teichmann@4812: } teichmann@4812: return fromToStep; teichmann@4812: } teichmann@4812: } teichmann@4812: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :