changeset 6932:b78d110135ec

(issue1451) Use distinct values for single_wq mode filtering instead of ranges.
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 27 Aug 2013 18:37:24 +0200
parents 2c8e5bad8699
children 468d9ebda4ce
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java
diffstat 1 files changed, 32 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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);
         }
 

http://dive4elements.wald.intevation.org