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; ingo@4152: ingo@4152: import java.util.Date; ingo@4152: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.model.Timerange; ingo@4152: ingo@4152: ingo@4152: public class HistoricalDischargeAccess extends RiverAccess { ingo@4152: ingo@4232: public static enum EvaluationMode { teichmann@5914: W(0), Q(1); teichmann@5914: teichmann@5914: private final int mode; teichmann@5914: teichmann@5914: EvaluationMode(int mode) { teichmann@5914: this.mode = mode; teichmann@5914: } teichmann@5914: teichmann@5914: public int getMode() { teichmann@5914: return mode; teichmann@5914: } ingo@4232: } ingo@4232: ingo@4152: public static final String DATA_EVALUATION_TIME = "year_range"; ingo@4233: public static final String DATA_EVALUATION_MODE = "historical_mode"; teichmann@5914: public static final String DATA_INPUT_VALUES = "historical_values"; teichmann@5914: public static final String DATA_REFERENCE_GAUGE = "reference_gauge"; ingo@4152: ingo@4152: private Timerange evaluationTimerange; ingo@4232: private EvaluationMode evaluationMode; ingo@4152: ingo@4233: private double[] qs; ingo@4233: private double[] ws; ingo@4233: teichmann@5914: private Long officialGaugeNumber; teichmann@5914: teichmann@5867: public HistoricalDischargeAccess(D4EArtifact artifact) { ingo@4152: super(artifact); ingo@4152: } ingo@4152: ingo@4233: /** ingo@4233: * This method returns the evaluation mode. The evaluation mode W is set, if ingo@4233: * the DATA_EVALUATION_MODE is 0. Otherwise, the evaluation mode Q is ingo@4233: * set. teichmann@4736: * ingo@4233: * @return EvaluationMode.W if the parameter historical_mode is set ingo@4233: * to 0, otherwise EvaluationMode.Q. ingo@4233: */ ingo@4232: public EvaluationMode getEvaluationMode() { ingo@4232: if (evaluationMode == null) { ingo@4233: int mode = getInteger(DATA_EVALUATION_MODE); ingo@4232: evaluationMode = mode == 0 ? EvaluationMode.W : EvaluationMode.Q; ingo@4232: } ingo@4232: ingo@4232: return evaluationMode; ingo@4232: } ingo@4232: teichmann@5914: ingo@4233: /** ingo@4233: * This method returns the time range specified by year_range ingo@4233: * parameter. This parameter has to be a string that consists of two long ingo@4233: * values (time millis since 1970) separated by a ';'. teichmann@4736: * ingo@4233: * @return the evaluation time range specified by year_range. ingo@4233: */ ingo@4152: public Timerange getEvaluationTimerange() { ingo@4152: if (evaluationTimerange == null) { ingo@4152: long[] startend = getLongArray(DATA_EVALUATION_TIME); ingo@4152: ingo@4152: if (startend != null && startend.length > 1) { ingo@4152: Date start = new Date(startend[0]); ingo@4152: Date end = new Date(startend[1]); ingo@4152: ingo@4152: evaluationTimerange = new Timerange(start, end); teichmann@5914: evaluationTimerange.sort(); ingo@4152: } ingo@4152: } ingo@4152: ingo@4152: return evaluationTimerange; ingo@4152: } ingo@4233: ingo@4233: /** ingo@4233: * This method returns the input Q values if the evaluation mode Q is set. ingo@4233: * Otherwise, this method will return a double array of length 0. The values ingo@4233: * returned by this method are extracted from string parameter ingo@4233: * historical_values. teichmann@4736: * ingo@4233: * @return the input Q values or a double array of length 0. ingo@4233: */ ingo@4233: public double[] getQs() { ingo@4233: if (qs == null) { ingo@4233: if (getEvaluationMode() == EvaluationMode.Q) { ingo@4233: qs = getDoubleArray(DATA_INPUT_VALUES); ingo@4233: } ingo@4233: else { ingo@4233: qs = new double[0]; ingo@4233: } ingo@4233: } ingo@4233: ingo@4233: return qs; ingo@4233: } ingo@4233: ingo@4233: /** ingo@4233: * This method returns the input W values if the evaluation mode W is set. ingo@4233: * Otherwise, this method will return a double array of length 0. The values ingo@4233: * returned by this method are extracted from string parameter ingo@4233: * historical_values. teichmann@4736: * ingo@4233: * @return the input W values or a double array of length 0. ingo@4233: */ ingo@4233: public double[] getWs() { ingo@4233: if (ws == null) { ingo@4233: if (getEvaluationMode() == EvaluationMode.W) { ingo@4233: ws = getDoubleArray(DATA_INPUT_VALUES); ingo@4233: } ingo@4233: else { ingo@4233: ws = new double[0]; ingo@4233: } ingo@4233: } ingo@4233: ingo@4233: return ws; ingo@4233: } teichmann@5914: teichmann@5914: public Long getOfficialGaugeNumber() { teichmann@5914: if (officialGaugeNumber == null) { teichmann@5914: officialGaugeNumber = getLong(DATA_REFERENCE_GAUGE); teichmann@5914: } teichmann@5914: return officialGaugeNumber; teichmann@5914: } ingo@4152: }