comparison 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
comparison
equal deleted inserted replaced
1278:4c3329db2536 1279:af6ad7522351
1 package de.intevation.flys.client.shared;
2
3
4 public final class DoubleUtils {
5
6 public static final String DEFAULT_DELIM = " ";
7
8
9 private DoubleUtils() {
10 }
11
12
13 public static Double getDouble(String value) {
14 try {
15 return Double.valueOf(value);
16 }
17 catch (NumberFormatException nfe) {
18 // do nothing
19 }
20
21 return null;
22 }
23
24
25 public static double[] getMinMax(String value) {
26 return getMinMax(value, DEFAULT_DELIM);
27 }
28
29
30 public static double[] getMinMax(String value, String delim) {
31 if (value == null) {
32 return null;
33 }
34
35 String[] values = value.split(delim);
36
37 int len = values != null ? values.length : 0;
38 double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
39
40 for (int i = 0; i < len; i++) {
41 Double d = getDouble(values[i]);
42
43 if (d != null) {
44 mm[0] = mm[0] < d ? mm[0] : d;
45 mm[1] = mm[1] > d ? mm[1] : d;
46 }
47 }
48
49 return mm[0] != Double.MAX_VALUE && mm[1] != -Double.MAX_VALUE
50 ? mm
51 : null;
52 }
53 }
54 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org