changeset 6603:90756201c488

Factor out filtering code in WaterlevelExporter
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 18 Jul 2013 13:26:33 +0200
parents 244beb29418e
children d3df835be006
files artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java
diffstat 1 files changed, 43 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- 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");

http://dive4elements.wald.intevation.org