changeset 3026:65b6e27c6f25

FixA: Use new data structures in Delta W(t) exporter. Removed obsolete code. flys-artifacts/trunk@4593 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 05 Jun 2012 16:25:51 +0000
parents 5d286d7e54cd
children 52aac4941d2a
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWT.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java flys-artifacts/src/main/java/de/intevation/flys/utils/KMIndex.java
diffstat 6 files changed, 51 insertions(+), 171 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 05 15:37:38 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 05 16:25:51 2012 +0000
@@ -1,3 +1,18 @@
+2012-06-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/DeltaWtExporter.java:
+	  Use new data structures for export.
+
+	* src/main/java/de/intevation/flys/utils/KMIndex.java:
+	  Implements java.lang.Iterable now.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWT.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java:
+	  Removed. Obsolete.
+
+	* src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java:
+	  Removed superfluous import.
+
 2012-06-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java:
@@ -486,7 +501,7 @@
 
 	* src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java,
 	  src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java:
-          (flipStickyAxis): Allow easy change of sticky axes.
+	  (flipStickyAxis): Allow easy change of sticky axes.
 
 2012-05-24	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWT.java	Tue Jun 05 15:37:38 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-package de.intevation.flys.artifacts.model.fixings;
-
-import java.io.Serializable;
-
-import java.util.Date;
-
-public class DeltaWT
-implements   Serializable
-{
-    protected double deltaW;
-    protected Date   date;
-    protected String description;
-
-    public DeltaWT() {
-    }
-
-    public DeltaWT(double deltaW, Date date, String description) {
-        this.deltaW      = deltaW;
-        this.date        = date;
-        this.description = description;
-    }
-
-    public double getDeltaW() {
-        return deltaW;
-    }
-
-    public void setDeltaW(double deltaW) {
-        this.deltaW = deltaW;
-    }
-
-    public Date getDate() {
-        return date;
-    }
-
-    public void setDate(Date date) {
-        this.date = date;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
-}
-// 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/DeltaWTsKM.java	Tue Jun 05 15:37:38 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-package de.intevation.flys.artifacts.model.fixings;
-
-import java.io.Serializable;
-
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
-
-public class DeltaWTsKM
-implements   Serializable
-{
-    public static final double EPSILON = 1e-5;
-
-    public static class KM
-    implements          Serializable, Comparable<KM>
-    {
-        protected double km;
-
-        protected List<DeltaWT> deltaWTs;
-
-        public KM() {
-            deltaWTs = new ArrayList<DeltaWT>();
-        }
-
-        public KM(double km) {
-            this();
-            this.km = km;
-        }
-
-        public double getKm() {
-            return km;
-        }
-
-        public void setKm(double km) {
-            this.km = km;
-        }
-
-        public List<DeltaWT> getDeltaWTs() {
-            return deltaWTs;
-        }
-
-        public void setDeltaWTs(List<DeltaWT> deltaWTs) {
-            this.deltaWTs = deltaWTs;
-        }
-
-        public void add(DeltaWT deltaWT) {
-            deltaWTs.add(deltaWT);
-        }
-
-        public int size() {
-            return deltaWTs.size();
-        }
-
-        @Override
-        public int compareTo(KM other) {
-            double d = km - other.km;
-            if (d < -EPSILON) return -1;
-            if (d >  EPSILON) return +1;
-            return 0;
-        }
-    } // class KM
-
-    protected List<KM> kms;
-
-    public DeltaWTsKM() {
-        this(10);
-    }
-
-    public DeltaWTsKM(int capacity) {
-        kms = new ArrayList<KM>(capacity);
-    }
-
-    public void add(KM km) {
-        kms.add(km);
-    }
-
-    public void sort() {
-        Collections.sort(kms);
-    }
-
-    public KM findByKm(double km) {
-        int idx = Collections.binarySearch(kms, new KM(km));
-        return idx >= 0 ? kms.get(idx) : null;
-    }
-
-    public List<KM> getKms() {
-        return kms;
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java	Tue Jun 05 15:37:38 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java	Tue Jun 05 16:25:51 2012 +0000
@@ -7,13 +7,14 @@
 
 import de.intevation.flys.artifacts.model.CalculationResult;
 
-import de.intevation.flys.artifacts.model.fixings.DeltaWT;
-import de.intevation.flys.artifacts.model.fixings.DeltaWTsKM;
 import de.intevation.flys.artifacts.model.fixings.FixResult;
+import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod;
+import de.intevation.flys.artifacts.model.fixings.QWD;
 
 import de.intevation.flys.artifacts.resources.Resources;
 
 import de.intevation.flys.utils.Formatter;
+import de.intevation.flys.utils.KMIndex;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -55,13 +56,13 @@
 
     public static final String DEFAULT_CSV_T_DESC_HEADER = "Beschreibung";
 
-    protected List<DeltaWTsKM> deltaWTsKMs;
+    protected List<KMIndex<AnalysisPeriod []>> analysisPeriods;
 
     @Override
     public void init(Document request, OutputStream out, CallContext context) {
         log.debug("DeltaWtExporter.init");
         super.init(request, out, context);
-        deltaWTsKMs = new ArrayList<DeltaWTsKM>();
+        analysisPeriods = new ArrayList<KMIndex<AnalysisPeriod []>>();
     }
 
     @Override
@@ -94,8 +95,7 @@
             log.warn("Invalid data stored in result.");
         }
         FixResult result = (FixResult)data;
-        // TODO: replace old code
-        //deltaWTsKMs.add(result.getDeltaWTsKM());
+        analysisPeriods.add(result.getAnalysisPeriods());
     }
 
     @Override
@@ -113,34 +113,33 @@
         DateFormat dF = DateFormat.getDateInstance(DateFormat.SHORT, locale);
 
         if (debug) {
-            log.debug("DeltaWTsKMs: " + deltaWTsKMs.size());
+            log.debug("AnalysisPeriods: " + analysisPeriods.size());
         }
 
-        for (DeltaWTsKM deltaWTsKM: deltaWTsKMs) {
-            List<DeltaWTsKM.KM> dkms = deltaWTsKM.getKms();
-            if (debug) {
-                log.debug("DeltaWTsKM.KM: " + dkms.size());
-            }
-            for (DeltaWTsKM.KM dkm: dkms) {
-                double km = dkm.getKm();
-                String kmS = kmF.format(km);
-                List<DeltaWT> deltaWTs = dkm.getDeltaWTs();
-                if (debug) {
-                    log.debug("deltaWTs: " + deltaWTs.size());
-                }
-                for (DeltaWT dwt: deltaWTs) {
-                    double deltaW = dwt.getDeltaW();
-                    Date   date   = dwt.getDate();
-                    String desc   = dwt.getDescription();
+        for (KMIndex<AnalysisPeriod []> periods: analysisPeriods) {
 
-                    String deltaWS = dwF.format(deltaW);
-                    String dateS   = dF.format(date);
+            for (KMIndex.Entry<AnalysisPeriod []> kmEntry: periods) {
 
-                    writer.writeNext(new String[] {
-                        kmS,
-                        deltaWS,
-                        dateS,
-                        desc != null ? desc : "" });
+                String kmS = kmF.format(kmEntry.getKm());
+
+                for (AnalysisPeriod period: kmEntry.getValue()) {
+                    QWD [] qwds = period.getQWDs();
+                    if (qwds != null) {
+                        for (QWD qwd: qwds) {
+                            double deltaW = qwd.getDeltaW();
+                            Date   date   = qwd.getDate();
+                            String desc   = qwd.getDescription();
+
+                            String deltaWS = dwF.format(deltaW);
+                            String dateS   = dF.format(date);
+
+                            writer.writeNext(new String[] {
+                                kmS,
+                                deltaWS,
+                                dateS,
+                                desc != null ? desc : "" });
+                        }
+                    }
                 }
             }
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java	Tue Jun 05 15:37:38 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java	Tue Jun 05 16:25:51 2012 +0000
@@ -2,8 +2,6 @@
 
 import org.apache.log4j.Logger;
 
-import java.util.Iterator;
-
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/KMIndex.java	Tue Jun 05 15:37:38 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/KMIndex.java	Tue Jun 05 16:25:51 2012 +0000
@@ -3,11 +3,12 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Iterator;
 
 import java.io.Serializable;
 
 public class KMIndex<A>
-implements   Serializable
+implements   Serializable, Iterable<KMIndex.Entry<A>>
 {
     public static final double EPSILON = 1e-4;
 
@@ -83,5 +84,9 @@
         int index = Collections.binarySearch(entries, new Entry(km));
         return index >= 0 ? entries.get(index) : null;
     }
+
+    public Iterator<Entry<A>> iterator() {
+        return entries.iterator();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org