Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java @ 3446:5325040d35e3
Adjusted i18n.
flys-artifacts/trunk@5109 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 23 Jul 2012 15:12:25 +0000 |
parents | 5642a83420f2 |
children |
rev | line source |
---|---|
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.utils; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
3 import java.util.Random; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
4 |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
5 import gnu.trove.TDoubleArrayList; |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
6 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
7 public class DataUtil |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
8 { |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
9 public static boolean guessWaterIncreasing(TDoubleArrayList data) { |
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
10 return guessWaterIncreasing(data, 0.05f); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
13 public static boolean guessWaterIncreasing(TDoubleArrayList data, float factor) { |
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
14 int N = data.size(); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 if (N < 2) return false; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
16 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
17 int samples = (int)(factor*N) + 1; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
18 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 int up = 0; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
20 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 Random rand = new Random(); |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
22 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 for (int i = 0; i < samples; ++i) { |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 int pos2 = rand.nextInt(N-1) + 1; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 int pos1 = rand.nextInt(pos2); |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
26 double w1 = data.getQuick(pos1); |
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
27 double w2 = data.getQuick(pos2); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 if (w2 > w1) ++up; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 } |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
30 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 return up > samples/2; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 } |
1982
8afd6a9bb244
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1678
diff
changeset
|
34 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |