[PATCH 2 of 2] (issue1451) Use distinct values for single_wq mode filtering instead of ranges

Wald Commits scm-commit at wald.intevation.org
Tue Aug 27 18:37:29 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1377621444 -7200
# Node ID b78d110135ec24ca887ac4cc470f2f917a0c6b53
# Parent  2c8e5bad86999168ee5081ed41bebb15cea781e9
(issue1451) Use distinct values for single_wq mode filtering instead of ranges.

diff -r 2c8e5bad8699 -r b78d110135ec artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java	Tue Aug 27 18:35:51 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java	Tue Aug 27 18:37:24 2013 +0200
@@ -274,6 +274,18 @@
         return list;
     }
 
+    private static List<ValueRange> filterByQValues(double[] values, List<ValueRange> ranges) {
+        List<ValueRange> list = new ArrayList<ValueRange>(ranges.size());
+        for (ValueRange r: ranges) {
+            for (double val: values) {
+                if (r.sameValue(val) && !list.contains(r)) {
+                    list.add(r);
+                }
+            }
+        }
+        return list;
+    }
+
     private static boolean isQ(D4EArtifact artifact) {
         Boolean b = artifact.getDataAsBoolean("wq_isq");
         return b != null && b;
@@ -286,25 +298,23 @@
 
     public static final Range Q_OUT_OF_RANGE = new Range(-10000, -9999);
 
-    private static Range singleQs(D4EArtifact artifact) {
+    private static double[] singleQs(D4EArtifact artifact) {
         String singleData = nn(artifact.getDataAsString("wq_single"));
-        double min =  Double.MAX_VALUE;
-        double max = -Double.MAX_VALUE;
+        String[] values = singleData.split(" ");
+        double[] ret = new double[values.length];
+        int i = 0;
 
-        for (String value: singleData.split(" ")) {
+        for (String value: values) {
             try {
-                double x = Double.parseDouble(value);
-                if (x < min) min = x;
-                if (x > max) max = x;
+                ret[i] = Double.parseDouble(value);
             }
             catch (NumberFormatException nfe) {
+                ret[i] = -1; // INVALID_Q_VALUE
             }
+            i++;
         }
 
-        return min == Double.MAX_VALUE
-            ? Q_OUT_OF_RANGE
-            : new Range(min, max);
-
+        return ret;
     }
 
     private static Range qRange(D4EArtifact artifact) {
@@ -383,21 +393,20 @@
             return Collections.<ValueRange>emptyList();
         }
 
-        Range qRange = isRange(artifact)
-            ? qRange(artifact)
-            : singleQs(artifact);
-
-        if (qRange == Q_OUT_OF_RANGE) {
-            qRange = tripleQRange(artifact);
+        if (isRange(artifact)) {
+            Range qRange = qRange(artifact);
+            if (qRange == Q_OUT_OF_RANGE) {
+                qRange = tripleQRange(artifact);
+            }
+            ranges = filterByQRange(qRange, ranges);
+            if (debug) {
+                log.debug("Q range filter: " + qRange);
+            }
+        } else {
+            ranges = filterByQValues(singleQs(artifact), ranges);
         }
 
         if (debug) {
-            log.debug("Q range filter: " + qRange);
-        }
-
-        ranges = filterByQRange(qRange, ranges);
-
-        if (debug) {
             log.debug("After q range filter: " + ranges);
         }
 


More information about the Dive4elements-commits mailing list