Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java @ 1163:2e0739853807
Fix build, added new DataUtil.
flys-artifacts/trunk@2700 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 12 Sep 2011 11:30:19 +0000 |
parents | |
children | 03fbf1b30e72 |
comparison
equal
deleted
inserted
replaced
1162:588798ef4791 | 1163:2e0739853807 |
---|---|
1 package de.intevation.flys.utils; | |
2 | |
3 import java.util.Random; | |
4 | |
5 import de.intevation.flys.artifacts.model.WKms; | |
6 | |
7 public class DataUtil | |
8 { | |
9 // TODO: resolve duplicate in WQKms | |
10 public static boolean guessWaterIncreasing(WKms wkms) { | |
11 return guessWaterIncreasing(wkms, 0.05f); | |
12 } | |
13 | |
14 // TODO: resolve duplicate in WQKms | |
15 public static boolean guessWaterIncreasing(WKms wkms, float factor) { | |
16 int N = wkms.size(); | |
17 if (N < 2) return false; | |
18 | |
19 int samples = (int)(factor*N) + 1; | |
20 | |
21 int up = 0; | |
22 | |
23 Random rand = new Random(); | |
24 | |
25 for (int i = 0; i < samples; ++i) { | |
26 int pos2 = rand.nextInt(N-1) + 1; | |
27 if (pos2 == 0) continue; | |
28 int pos1 = rand.nextInt(pos2); | |
29 double w1 = wkms.getW(pos1); | |
30 double w2 = wkms.getW(pos2); | |
31 if (w2 > w1) ++up; | |
32 } | |
33 | |
34 return up > samples/2; | |
35 } | |
36 } |