changeset 1075:b5314ea024c6

Use Intervall class for daily Probe objects.
author Tom Gottfried <tom@intevation.de>
date Fri, 30 Sep 2016 17:41:31 +0200
parents 90bc64e74e4a
children 4ce4bd48c260
files src/main/java/de/intevation/lada/factory/ProbeFactory.java
diffstat 1 files changed, 21 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/factory/ProbeFactory.java	Fri Sep 30 17:38:04 2016 +0200
+++ b/src/main/java/de/intevation/lada/factory/ProbeFactory.java	Fri Sep 30 17:41:31 2016 +0200
@@ -48,12 +48,15 @@
     private static Hashtable<String, int[]> fieldsTable;
 
     public ProbeFactory() {
+        int[] T = { Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR, 1 };
+
         int[] M = { Calendar.MONTH, Calendar.DAY_OF_MONTH, 1 };
         int[] Q = { Calendar.MONTH, Calendar.DAY_OF_MONTH, 3 };
         int[] H = { Calendar.MONTH, Calendar.DAY_OF_MONTH, 6 };
 
         this.fieldsTable = new Hashtable<String, int[]>();
 
+        this.fieldsTable.put("T", T);
         this.fieldsTable.put("M", M);
         this.fieldsTable.put("Q", Q);
         this.fieldsTable.put("H", H);
@@ -110,35 +113,36 @@
         * @return the adjusted Calendar object.
         */
         private Calendar adjustSubIntField(Calendar cal, int teil) {
-            int intField = cal.get(intervallField);
-            cal.set(
-                intervallField,
-                intField - intField % intervallFactor
-            );
-            cal.set(subIntField, offset + Math.min(teil, getDuration()));
+            int intValue = cal.get(intervallField);
+            intValue = intValue - intValue % intervallFactor;
+            cal.set(intervallField, intValue);
+
+            int subIntValue = intervallField == subIntField ? intValue : 0
+                + offset + Math.min(teil, getDuration());
+            cal.set(subIntField, subIntValue);
+
             return cal;
         }
 
         /**
-         * Get sum of actual maxima for given field from actual field value
-         * for the next factor values of iterField.
-         *
-         * @param calendar  Time to start from
-         *
-         * @return the sum of maxima for the field values specified with
-         *         field and factor.
+         * @return sum of actual maxima for subIntField from beginning of
+         * actual intervall for the next intervallFactor values intervallField
+         * or just intervallFactor, if subIntField == intervallField.
          */
         private int getDuration() {
+            if (subIntField == intervallField) {
+                return intervallFactor;
+            }
             logger.debug("## calculate maximum ##");
             int duration = 0;
             Calendar tmp = (Calendar)from.clone();
             /* reset to beginning of intervall, e.g. first day of quarter
              * to compensate possible overflow if
              * teilVon > maximum of intervallField: */
-            int fromIntField = from.get(intervallField);
+            int intValue = from.get(intervallField);
             tmp.set(
                 intervallField,
-                fromIntField - fromIntField % intervallFactor
+                intValue - intValue % intervallFactor
             );
             tmp.set(subIntField, tmp.getActualMinimum(subIntField));
             logger.debug(tmp);
@@ -245,11 +249,8 @@
         end.setTime(interval[1]);
         int endDay = end.get(Calendar.DAY_OF_YEAR);
 
-        // If fixed interval (T, W, W2, W4)
-        if ("T".equals(messprogramm.getProbenintervall())) {
-            proben.addAll(generate(messprogramm, start, end, 1));
-        }
-        else if ("W".equals(messprogramm.getProbenintervall())) {
+        // If fixed interval (W, W2, W4)
+        if ("W".equals(messprogramm.getProbenintervall())) {
             Calendar realStart = getMonday(start);
             proben.addAll(generate(messprogramm, realStart, end, 7));
         }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)