[PATCH] Factor out filtering code in WaterlevelExporter

Wald Commits scm-commit at wald.intevation.org
Thu Jul 18 13:26:52 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1374146793 -7200
# Node ID 90756201c488dc337581eddcf820f6a9b076a25f
# Parent  244beb29418e1d88ab654cc2996b0fde2bfde43c
Factor out filtering code in WaterlevelExporter

diff -r 244beb29418e -r 90756201c488 artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Thu Jul 18 13:25:29 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Thu Jul 18 13:26:33 2013 +0200
@@ -360,45 +360,54 @@
         }
         /* Append the official fixing at the bottom */
         for (WQKms wqkms: officalFixings) {
-            logger.debug("Exporting official fixing fromKM: " + first +
-                    " toKM: " + last);
-            /* To handle upstream / downstream and to limit
-             * the officialFixings to the calculation distance
-             * we create a new wqkms object here and fill it only
-             * with the relevant data. */
-            if (first.isNaN() || last.isNaN()) {
-                logger.warn("Exporting official fixing without valid first/last.");
-                wQKms2CSV(writer, wqkms, atGauge, isQ);
-                return;
-            }
-            int firstIdx = first > last ? wqkms.size() - 1 : 0;
-            int lastIdx  = first > last ? 0 : wqkms.size() -1;
-            WQKms filtered = new WQKms (wqkms.size());
-            filtered.setReferenceSystem(wqkms.getReferenceSystem());
-            filtered.setName(wqkms.getName());
-            double [] dp = new double [3];
+            wQKms2CSV(writer, filterWQKms(wqkms, first, last), atGauge, isQ);
+        }
+    }
 
-            if (first > last) {
-                for (int i = wqkms.size() - 1; i >= 0; i--) {
-                    dp = wqkms.get(i, dp);
-                    if (dp[2] < first && dp[2] > last) {
-                        filtered.add(dp[0], dp[1], dp[2]);
-                    }
-                }
-            } else {
-                for (int i = 0; i < wqkms.size(); i++) {
-                    dp = wqkms.get(i, dp);
-                    if (dp[2] < last && dp[2] > first) {
-                        filtered.add(dp[0], dp[1], dp[2]);
-                    }
+
+    /** Filter a wqkms object to a distance.
+     *
+     * To handle upstream / downstream and to limit
+     * the officialFixings to the calculation distance
+     * we create a new wqkms object here and fill it only
+     * with the relevant data.
+     *
+     * @param wqkms: The WQKms Object to filter
+     * @param first: The fist kilometer of the range
+     * @param last: The last kilometer of the range
+     *
+     * @return A new WQKms with the relevant data sorted by direction
+     */
+    private WQKms filterWQKms(WQKms wqkms, Double first, Double last) {
+        if (first.isNaN() || last.isNaN()) {
+            logger.warn("Filtering official fixing without valid first/last.");
+            return wqkms;
+        }
+        int firstIdx = first > last ? wqkms.size() - 1 : 0;
+        int lastIdx  = first > last ? 0 : wqkms.size() -1;
+        WQKms filtered = new WQKms (wqkms.size());
+        filtered.setReferenceSystem(wqkms.getReferenceSystem());
+        filtered.setName(wqkms.getName());
+        double [] dp = new double [3];
+
+        if (first > last) {
+            for (int i = wqkms.size() - 1; i >= 0; i--) {
+                dp = wqkms.get(i, dp);
+                if (dp[2] < first && dp[2] > last) {
+                    filtered.add(dp[0], dp[1], dp[2]);
                 }
             }
-            wQKms2CSV(writer, filtered, atGauge, isQ);
+        } else {
+            for (int i = 0; i < wqkms.size(); i++) {
+                dp = wqkms.get(i, dp);
+                if (dp[2] < last && dp[2] > first) {
+                    filtered.add(dp[0], dp[1], dp[2]);
+                }
+            }
         }
+        return filtered;
     }
-/*
-    private WQKms filterWQKms (wkqm
-*/
+
 
     protected void writeCSVMeta(CSVWriter writer) {
         logger.info("WaterlevelExporter.writeCSVMeta");


More information about the Dive4elements-commits mailing list