diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java @ 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 619fe13e2397
children 5d286d7e54cd
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());
             }
         }
 

http://dive4elements.wald.intevation.org