[PATCH 2 of 2] (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors

Wald Commits scm-commit at wald.intevation.org
Wed Dec 11 17:13:48 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1386778406 -3600
# Node ID 270946b97539dcaa225d5fa406891cff28c6a619
# Parent  0141908fafe08dda80f027c263ed77b8cca05fec
(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

diff -r 0141908fafe0 -r 270946b97539 artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadM3AProcessor.java
--- 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.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);
diff -r 0141908fafe0 -r 270946b97539 artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java
--- /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);
+    }
+}
+
diff -r 0141908fafe0 -r 270946b97539 artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadTAProcessor.java
--- 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.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);


More information about the Dive4elements-commits mailing list