changeset 4926:1e379598c47a

Fixed dc:fromValue/toValue (now handles values in locations as numbers).
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 31 Jan 2013 10:18:16 +0100
parents 57609ffb3843
children eb1cde786abf
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java
diffstat 1 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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")) {

http://dive4elements.wald.intevation.org