annotate flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java @ 4241:49cb65d5932d

Improved the historical discharge calculation. The calculation now creates new HistoricalWQKms (new subclass of WQKms). Those WQKms are used to create new facets from (new) type 'HistoricalDischargeCurveFacet'. The chart generator is improved to support those facets.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 24 Oct 2012 14:34:35 +0200
parents 51ed89b754ae
children
rev   line source
1279
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.shared;
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 public final class DoubleUtils {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 public static final String DEFAULT_DELIM = " ";
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 private DoubleUtils() {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 public static Double getDouble(String value) {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 try {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 return Double.valueOf(value);
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 catch (NumberFormatException nfe) {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 // do nothing
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 return null;
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 public static double[] getMinMax(String value) {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 return getMinMax(value, DEFAULT_DELIM);
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 public static double[] getMinMax(String value, String delim) {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 if (value == null) {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 return null;
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 String[] values = value.split(delim);
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 int len = values != null ? values.length : 0;
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 for (int i = 0; i < len; i++) {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 Double d = getDouble(values[i]);
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 if (d != null) {
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 mm[0] = mm[0] < d ? mm[0] : d;
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 mm[1] = mm[1] > d ? mm[1] : d;
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 return mm[0] != Double.MAX_VALUE && mm[1] != -Double.MAX_VALUE
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 ? mm
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 : null;
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 }
1616
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
53
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
54 /** toIndex is not inclusive, fromIndex is. */
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
55 static void fill(double[] array, int fromIndex, int toIndex, double val) {
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
56 for (int i = fromIndex; i < toIndex; i++) {
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
57 array[i] = val;
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
58 }
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
59 }
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
60
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
61 /** @see java.util.Arrays.copyOf */
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
62 public static double[] copyOf(double[] toCopy, int newLen) {
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
63 double[] nArray = new double[newLen];
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
64
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
65 if (toCopy == null) {
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
66 fill(nArray, 0, nArray.length, 0d);
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
67 return nArray;
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
68 }
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
69
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
70 int goTo = (newLen < toCopy.length)
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
71 ? newLen
2905
51ed89b754ae FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1616
diff changeset
72 : toCopy.length;
1616
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
73
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
74 for (int i = 0; i < goTo; i++) {
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
75 nArray[i] = toCopy[i];
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
76 }
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
77 fill (nArray, goTo, nArray.length, 0d);
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
78 return nArray;
ff8312688cd5 Added utility functions for double arrays.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1279
diff changeset
79 }
1279
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 }
af6ad7522351 Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org