changeset 7685:270946b97539

(issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors This also removes duplicated code by basing the TA and MA processors on the same class
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 11 Dec 2013 17:13:26 +0100
parents 0141908fafe0
children 7484132b2fbb
files artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadM3AProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadTAProcessor.java
diffstat 3 files changed, 74 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadM3AProcessor.java	Wed Dec 11 17:11:43 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadM3AProcessor.java	Wed Dec 11 17:13:26 2013 +0100
@@ -5,26 +5,14 @@
  * and comes with ABSOLUTELY NO WARRANTY! Check out the
  * documentation coming with Dive4Elements River for details.
  */
-
 package org.dive4elements.river.exports.process;
 
-import java.util.Set;
-
 import org.apache.log4j.Logger;
-import org.jfree.data.xy.XYSeries;
 
-import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
-import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.exports.DiagramGenerator;
-import org.dive4elements.river.exports.StyledSeriesBuilder;
-import org.dive4elements.river.jfree.StyledXYSeries;
-import org.dive4elements.river.themes.ThemeDocument;
 
-import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
-import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
-
-public class SedimentLoadM3AProcessor extends DefaultProcessor {
+public class SedimentLoadM3AProcessor extends SedimentLoadProcessor {
 
     private final static Logger logger =
             Logger.getLogger(SedimentLoadM3AProcessor.class);
@@ -34,43 +22,6 @@
     public static final String I18N_YAXIS_LABEL_DEFAULT = "[m\u00b3/a]";
 
     @Override
-    public void doOut(
-            DiagramGenerator generator,
-            ArtifactAndFacet bundle,
-            ThemeDocument    theme,
-            boolean          visible) {
-        logger.debug("doOut " + bundle.getFacetName());
-        CallContext context = generator.getCallContext();
-        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
-                theme);
-        Object data = bundle.getData(context);
-        String facetName = bundle.getFacetName();
-        double [][] points;
-
-        if (FacetTypes.IS.SEDIMENT_LOAD_M3A(facetName)) {
-            points = (double[][]) data;
-        } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) {
-            SedimentLoad load = (SedimentLoad) data;
-            Set<Double> kms = load.getKms();
-            points = new double[2][kms.size()];
-            int counter = 0;
-            for (Double km: kms) {
-                SedimentLoadFraction fraction = load.getFraction(km);
-                points[0][counter] = km;
-                points[1][counter] = fraction.getUnknown();
-                counter++;
-            }
-        } else {
-            logger.error("Unknown facet name: " + facetName);
-            return;
-        }
-
-        StyledSeriesBuilder.addPoints(series, points, true);
-
-        generator.addAxisSeries(series, axisName, visible);
-    }
-
-    @Override
     public boolean canHandle(String facettype) {
         return FacetTypes.IS.SEDIMENT_LOAD_M3A(facettype) ||
             FacetTypes.SEDIMENT_LOAD_M3A_UNKNOWN.equals(facettype);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java	Wed Dec 11 17:13:26 2013 +0100
@@ -0,0 +1,72 @@
+/* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.exports.process;
+
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
+
+// Base class for SedimantLoad$UNITProcessors
+public class SedimentLoadProcessor extends DefaultProcessor
+{
+    private final static Logger logger =
+            Logger.getLogger(SedimentLoadProcessor.class);
+
+    @Override
+    public void doOut(
+            DiagramGenerator generator,
+            ArtifactAndFacet bundle,
+            ThemeDocument    theme,
+            boolean          visible) {
+        logger.debug("doOut " + bundle.getFacetName());
+        CallContext context = generator.getCallContext();
+        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
+                false, // Handle NaN
+                theme);
+        Object data = bundle.getData(context);
+        String facetName = bundle.getFacetName();
+        double [][] points;
+
+        if (FacetTypes.IS.SEDIMENT_LOAD_M3A(facetName) ||
+                FacetTypes.IS.SEDIMENT_LOAD_TA(facetName)) {
+            points = (double[][]) data;
+        } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) {
+            SedimentLoad load = (SedimentLoad) data;
+            Set<Double> kms = load.getKms();
+            points = new double[2][kms.size()];
+            int counter = 0;
+            for (Double km: kms) {
+                SedimentLoadFraction fraction = load.getFraction(km);
+                points[0][counter] = km;
+                points[1][counter] = fraction.getUnknown();
+                counter++;
+            }
+        } else {
+            logger.error("Unknown facet name: " + facetName);
+            return;
+        }
+
+        StyledSeriesBuilder.addPoints(series, points, false); // Keep NaN
+
+        generator.addAxisSeries(series, axisName, visible);
+    }
+}
+
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadTAProcessor.java	Wed Dec 11 17:11:43 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadTAProcessor.java	Wed Dec 11 17:13:26 2013 +0100
@@ -8,23 +8,12 @@
 
 package org.dive4elements.river.exports.process;
 
-import java.util.Set;
-
 import org.apache.log4j.Logger;
-import org.jfree.data.xy.XYSeries;
 
-import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
-import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.exports.DiagramGenerator;
-import org.dive4elements.river.exports.StyledSeriesBuilder;
-import org.dive4elements.river.jfree.StyledXYSeries;
-import org.dive4elements.river.themes.ThemeDocument;
 
-import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
-import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
-
-public class SedimentLoadTAProcessor extends DefaultProcessor {
+public class SedimentLoadTAProcessor extends SedimentLoadProcessor{
 
     private final static Logger logger =
             Logger.getLogger(SedimentLoadTAProcessor.class);
@@ -34,43 +23,6 @@
     public static final String I18N_YAXIS_LABEL_DEFAULT = "[t/a]";
 
     @Override
-    public void doOut(
-            DiagramGenerator generator,
-            ArtifactAndFacet bundle,
-            ThemeDocument    theme,
-            boolean          visible) {
-        logger.debug("doOut " + bundle.getFacetName());
-        CallContext context = generator.getCallContext();
-        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
-                theme);
-        Object data = bundle.getData(context);
-        String facetName = bundle.getFacetName();
-        double [][] points;
-
-        if (FacetTypes.IS.SEDIMENT_LOAD_TA(facetName)) {
-            points = (double[][]) data;
-        } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) {
-            SedimentLoad load = (SedimentLoad) data;
-            Set<Double> kms = load.getKms();
-            points = new double[2][kms.size()];
-            int counter = 0;
-            for (Double km: kms) {
-                SedimentLoadFraction fraction = load.getFraction(km);
-                points[0][counter] = km;
-                points[1][counter] = fraction.getUnknown();
-                counter++;
-            }
-        } else {
-            logger.error("Unknown facet name: " + facetName);
-            return;
-        }
-
-        StyledSeriesBuilder.addPoints(series, points, true);
-
-        generator.addAxisSeries(series, axisName, visible);
-    }
-
-    @Override
     public boolean canHandle(String facettype) {
         return FacetTypes.IS.SEDIMENT_LOAD_TA(facettype) ||
             FacetTypes.SEDIMENT_LOAD_TA_UNKNOWN.equals(facettype);

http://dive4elements.wald.intevation.org