[PATCH] (issue1754) Handle inverted presentation in BedDifference exporter

Wald Commits scm-commit at wald.intevation.org
Fri Mar 27 18:59:40 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427479167 -3600
# Node ID 999b9ab16738c17e2e7b80da9e88d3becbc23a8d
# Parent  9db1f48bfea99ccbfc82d263e644bc82e7012cf4
(issue1754) Handle inverted presentation in BedDifference exporter

    This als removes dead (would have triggered an exception in pdf export)
    code to handle beddiff results which are not "BedDiffYearResults"

diff -r 9db1f48bfea9 -r 999b9ab16738 artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java	Fri Mar 27 18:54:03 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java	Fri Mar 27 18:59:27 2015 +0100
@@ -17,6 +17,7 @@
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Date;
+import java.util.Collections;
 import java.text.DateFormat;
 
 import org.apache.log4j.Logger;
@@ -87,57 +88,57 @@
         results = new BedDifferencesResult[0];
     }
 
+    protected List<String[]> data2StringArrays() {
+        NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
+        NumberFormat mf = Formatter.getMeterFormat(context);
+        D4EArtifact arti = (D4EArtifact) master;
+        RangeAccess access = new RangeAccess(arti);
+
+        List<String[]> retval = new ArrayList<String[]>();
+
+        for (BedDifferencesResult result : results) {
+            BedDiffYearResult yResult = (BedDiffYearResult) result;
+            String desc = result.getDiffDescription();
+            double[][] kms = yResult.getDifferencesData();
+            double[][] sounding1 = yResult.getSoundingWidth1Data();
+            double[][] sounding2 = yResult.getSoundingWidth2Data();
+            double[][] gap1 = yResult.getDataGap1Data();
+            double[][] gap2 = yResult.getDataGap2Data();
+
+            for (int j = 0; j < kms[0].length; j++) {
+                String sound1 = !Double.isNaN(sounding1[1][j])
+                    ? mf.format(sounding1[1][j])
+                    : "";
+                String sound2 = !Double.isNaN(sounding2[1][j])
+                    ? mf.format(sounding2[1][j])
+                    : "";
+                String g1 = !Double.isNaN(gap1[1][j])
+                    ? mf.format(gap1[1][j])
+                    : "";
+                String g2 = !Double.isNaN(gap2[1][j])
+                    ? mf.format(gap2[1][j])
+                    : "";
+                retval.add(new String[] {
+                    kmf.format(kms[0][j]),
+                    desc,
+                    mf.format(kms[1][j]),
+                    sound1,
+                    sound2,
+                    g1,
+                    g2
+                    });
+            }
+        }
+       if (access.getFrom() > access.getTo()) {
+           Collections.reverse(retval);
+       }
+       return retval;
+    }
     @Override
     protected void writeCSVData(CSVWriter writer) throws IOException {
         writeCSVHeader(writer);
 
-        NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
-        NumberFormat mf = Formatter.getMeterFormat(context);
-        for (BedDifferencesResult result : results) {
-            if (result instanceof BedDiffYearResult) {
-                BedDiffYearResult yResult = (BedDiffYearResult) result;
-                String desc = result.getDiffDescription();
-                double[][] kms = yResult.getDifferencesData();
-                double[][] sounding1 = yResult.getSoundingWidth1Data();
-                double[][] sounding2 = yResult.getSoundingWidth2Data();
-                double[][] gap1 = yResult.getDataGap1Data();
-                double[][] gap2 = yResult.getDataGap2Data();
-                for (int j = 0; j < kms[0].length; j++) {
-                    String sound1 = !Double.isNaN(sounding1[1][j])
-                        ? mf.format(sounding1[1][j])
-                        : "";
-                    String sound2 = !Double.isNaN(sounding2[1][j])
-                        ? mf.format(sounding2[1][j])
-                        : "";
-                    String g1 = !Double.isNaN(gap1[1][j])
-                        ? mf.format(gap1[1][j])
-                        : "";
-                    String g2 = !Double.isNaN(gap2[1][j])
-                        ? mf.format(gap2[1][j])
-                        : "";
-                    writer.writeNext(new String[] {
-                        kmf.format(kms[0][j]),
-                        desc,
-                        mf.format(kms[1][j]),
-                        sound1,
-                        sound2,
-                        g1,
-                        g2
-                        });
-                }
-            }
-            else {
-                double[][] kms = result.getDifferencesData();
-                String desc = result.getDiffDescription();
-                for (int j = 0; j < kms[0].length; j++) {
-                    writer.writeNext(new String[] {
-                        kmf.format(kms[0][j]),
-                        desc,
-                        mf.format(kms[1][j]),
-                        });
-                }
-            }
-        }
+        writer.writeAll(data2StringArrays());
     }
 
     @Override
@@ -216,27 +217,8 @@
         BedDifferenceJRDataSource source = new BedDifferenceJRDataSource();
 
         addMetaData(source);
-        NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
-        NumberFormat mf = Formatter.getMeterFormat(context);
-        for (BedDifferencesResult result: results) {
-            BedDiffYearResult yResult = (BedDiffYearResult) result;
-            double[][] kms = result.getDifferencesData();
-            String desc = result.getDiffDescription();
-            double[][] sounding1 = yResult.getSoundingWidth1Data();
-            double[][] sounding2 = yResult.getSoundingWidth2Data();
-            double[][] gap1 = yResult.getDataGap1Data();
-            double[][] gap2 = yResult.getDataGap2Data();
-            for (int j = 0; j < kms[0].length; j++) {
-                source.addData(new String[] {
-                    kmf.format(kms[0][j]),
-                    desc,
-                    mf.format(kms[1][j]),
-                    mf.format(sounding1[1][j]),
-                    mf.format(sounding2[1][j]),
-                    mf.format(gap1[1][j]),
-                    mf.format(gap2[1][j])
-                    });
-            }
+        for (String[] str: data2StringArrays()) {
+            source.addData(str);
         }
         return source;
     }


More information about the Dive4Elements-commits mailing list