diff flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java @ 1279:af6ad7522351

Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription. flys-client/trunk@2861 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 29 Sep 2011 09:14:41 +0000
parents
children ff8312688cd5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java	Thu Sep 29 09:14:41 2011 +0000
@@ -0,0 +1,54 @@
+package de.intevation.flys.client.shared;
+
+
+public final class DoubleUtils {
+
+    public static final String DEFAULT_DELIM = " ";
+
+
+    private DoubleUtils() {
+    }
+
+
+    public static Double getDouble(String value) {
+        try {
+            return Double.valueOf(value);
+        }
+        catch (NumberFormatException nfe) {
+            // do nothing
+        }
+
+        return null;
+    }
+
+
+    public static double[] getMinMax(String value) {
+        return getMinMax(value, DEFAULT_DELIM);
+    }
+
+
+    public static double[] getMinMax(String value, String delim) {
+        if (value == null) {
+            return null;
+        }
+
+        String[] values = value.split(delim);
+
+        int     len = values != null ? values.length : 0;
+        double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
+
+        for (int i = 0; i < len; i++) {
+            Double d = getDouble(values[i]);
+
+            if (d != null) {
+                mm[0] = mm[0] < d ? mm[0] : d;
+                mm[1] = mm[1] > d ? mm[1] : d;
+            }
+        }
+
+        return mm[0] != Double.MAX_VALUE && mm[1] != -Double.MAX_VALUE
+            ? mm
+            : null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org