changeset 3003:e5e6363e6cba

FixA: Explicit model for date ranges. flys-artifacts/trunk@4559 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 30 May 2012 14:45:36 +0000
parents e54dd69d306f
children a86c1a9456ae
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DateRange.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java
diffstat 3 files changed, 76 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Wed May 30 13:46:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Wed May 30 14:45:36 2012 +0000
@@ -1,13 +1,16 @@
 package de.intevation.flys.artifacts;
 
+import de.intevation.artifactdatabase.data.StateData;
+
+import de.intevation.flys.artifacts.model.fixings.DateRange;
+
+import de.intevation.flys.utils.FLYSUtils;
+
+import gnu.trove.TDoubleArrayList;
+
 import java.util.ArrayList;
 import java.util.Arrays;
-
-import de.intevation.artifactdatabase.data.StateData;
-
-import gnu.trove.TDoubleArrayList;
-
-import de.intevation.flys.utils.FLYSUtils;
+import java.util.Date;
 
 import org.apache.log4j.Logger;
 
@@ -34,7 +37,7 @@
     protected Long referenceStart;
     protected Long referenceEnd;
 
-    protected long [][] analysisPeriods;
+    protected DateRange [] analysisPeriods;
 
     protected int [] events;
 
@@ -297,7 +300,7 @@
         return referenceEnd;
     }
 
-    public long [][] getAnalysisPeriods() {
+    public DateRange [] getAnalysisPeriods() {
         if (analysisPeriods == null) {
             StateData sd = artifact.getData("ana_data");
 
@@ -307,18 +310,17 @@
             }
 
             String data = (String)sd.getValue();
-            String[] pairs = data.split(";");
+            String[] pairs = data.split("\\s*;\\s*");
 
-            ArrayList<long[]> aPs = new ArrayList<long[]>(pairs.length);
+            ArrayList<DateRange> aPs = new ArrayList<DateRange>(pairs.length);
 
             for (int i = 0; i < pairs.length; i++) {
-                String[] fromTo = pairs[i].split(",");
+                String[] fromTo = pairs[i].split("\\s*,\\s*");
                 if (fromTo.length >= 2) {
                     try {
-                        aPs.add(new long [] {
-                            Long.parseLong(fromTo[0]),
-                            Long.parseLong(fromTo[1])
-                        });
+                        Date from = new Date(Long.parseLong(fromTo[0]));
+                        Date to   = new Date(Long.parseLong(fromTo[1]));
+                        aPs.add(new DateRange(from, to));
                     }
                     catch (NumberFormatException nfe) {
                         log.warn("ana_data contains no long values.", nfe);
@@ -326,13 +328,14 @@
                 }
             }
 
-            analysisPeriods = aPs.toArray(new long[aPs.size()][]);
+            analysisPeriods = aPs.toArray(new DateRange[aPs.size()]);
         }
 
         if (log.isDebugEnabled()) {
             for (int i = 0; i < analysisPeriods.length; ++i) {
-                long [] ap = analysisPeriods[i];
-                log.debug("analysis period " + ap[0] + " - " + ap[1]);
+                DateRange ap = analysisPeriods[i];
+                log.debug("analysis period " +
+                    ap.getFrom() + " - " + ap.getTo());
             }
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DateRange.java	Wed May 30 14:45:36 2012 +0000
@@ -0,0 +1,34 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import java.util.Date;
+
+import java.io.Serializable;
+
+public class DateRange
+implements   Serializable
+{
+    protected Date from;
+    protected Date to;
+
+    public DateRange(Date from, Date to) {
+        this.from = from;
+        this.to   = to;
+    }
+
+    public Date getFrom() {
+        return from;
+    }
+
+    public void setFrom(Date from) {
+        this.from = from;
+    }
+
+    public Date getTo() {
+        return to;
+    }
+
+    public void setTo(Date to) {
+        this.to = to;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Wed May 30 13:46:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Wed May 30 14:45:36 2012 +0000
@@ -24,7 +24,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Date;
 
 import org.apache.commons.math.MathException;
 
@@ -39,31 +38,31 @@
 {
     private static Logger log = Logger.getLogger(FixCalculation.class);
 
-    protected String    river;
-    protected double    from;
-    protected double    to;
-    protected double    step;
-    protected boolean   preprocessing;
-    protected String    function;
-    protected int []    events;
-    protected long [][] analysisPeriods;
-    protected int       qSectorStart;
-    protected int       qSectorEnd;
+    protected String       river;
+    protected double       from;
+    protected double       to;
+    protected double       step;
+    protected boolean      preprocessing;
+    protected String       function;
+    protected int []       events;
+    protected DateRange [] analysisPeriods;
+    protected int          qSectorStart;
+    protected int          qSectorEnd;
 
     public FixCalculation() {
     }
 
     public FixCalculation(FixationArtifactAccess access) {
 
-        String    river           = access.getRiver();
-        Double    from            = access.getFrom();
-        Double    to              = access.getTo();
-        Double    step            = access.getStep();
-        String    function        = access.getFunction();
-        int []    events          = access.getEvents();
-        long [][] analysisPeriods = access.getAnalysisPeriods();
-        Integer   qSectorStart    = access.getQSectorStart();
-        Integer   qSectorEnd      = access.getQSectorEnd();
+        String    river              = access.getRiver();
+        Double    from               = access.getFrom();
+        Double    to                 = access.getTo();
+        Double    step               = access.getStep();
+        String    function           = access.getFunction();
+        int []    events             = access.getEvents();
+        DateRange [] analysisPeriods = access.getAnalysisPeriods();
+        Integer   qSectorStart       = access.getQSectorStart();
+        Integer   qSectorEnd         = access.getQSectorEnd();
 
         if (river == null) {
             // TODO: i18n
@@ -369,14 +368,12 @@
         for (int i = 0; i < columns.length; ++i) {
 
             // Construct filter for period.
-            long [] period = analysisPeriods[i];
+            DateRange period = analysisPeriods[i];
 
             AndFilter filter = new AndFilter();
 
             DateRangeFilter dateRangeFilter =
-                new DateRangeFilter(
-                    new Date(period[0]),
-                    new Date(period[1]));
+                new DateRangeFilter(period.getFrom(), period.getTo());
 
             filter.add(dateRangeFilter);
             filter.add(sectorRangeFilter);

http://dive4elements.wald.intevation.org