[Dive4elements-commits] [PATCH] Fixed dc:fromValue/toValue (now handles values in locations as numbers)

Wald Commits scm-commit at wald.intevation.org
Thu Jan 31 10:18:20 CET 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1359623896 -3600
# Node ID 1e379598c47a4b12feab5123e1a09bfc9c671f29
# Parent  57609ffb3843fbc25a3e6165b526e8e187a4e973
Fixed dc:fromValue/toValue (now handles values in locations as numbers).

diff -r 57609ffb3843 -r 1e379598c47a flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Thu Jan 31 09:29:24 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Thu Jan 31 10:18:16 2013 +0100
@@ -101,11 +101,23 @@
                     if (!(locations instanceof String)) {
                         return -Double.MAX_VALUE;
                     }
-                    else {
-                        String loc = ((String)locations).replace(" ", "");
-                        String[] split = loc.split(",");
-                        Arrays.sort(split);
-                        return split[0];
+                    String loc = ((String)locations).replace(" ", "");
+                    String[] split = loc.split(",");
+                    if (split.length < 1) {
+                        return -Double.MAX_VALUE;
+                    }
+                    try {
+                        double min = Double.parseDouble(split[0]);
+                        for (int i = 1; i < split.length; ++i) {
+                            double v = Double.parseDouble(split[i]);
+                            if (v < min) {
+                                min = v;
+                            }
+                        }
+                        return min;
+                    }
+                    catch (NumberFormatException nfe) {
+                        return -Double.MAX_VALUE;
                     }
                 }
                 else if (mode.equals("distance")) {
@@ -145,11 +157,23 @@
                     if (!(locations instanceof String)) {
                         return Double.MAX_VALUE;
                     }
-                    else {
+                    try {
                         String loc = ((String)locations).replace(" ", "");
                         String[] split = loc.split(",");
-                        Arrays.sort(split);
-                        return split[split.length - 1];
+                        if (split.length < 1) {
+                            return Double.MAX_VALUE;
+                        }
+                        double max = Double.parseDouble(split[0]);
+                        for (int i = 1; i < split.length; ++i) {
+                            double v = Double.parseDouble(split[i]);
+                            if (v > max) {
+                                max = v;
+                            }
+                        }
+                        return max;
+                    }
+                    catch (NumberFormatException nfe) {
+                        return Double.MAX_VALUE;
                     }
                 }
                 else if (mode.equals("distance")) {


More information about the Dive4elements-commits mailing list