Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 1678:03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
flys-artifacts/trunk@2895 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 05 Oct 2011 13:16:44 +0000 |
parents | 821aaceb2776 |
children | bda04ae1154f |
comparison
equal
deleted
inserted
replaced
1677:dd9dfe1e48fa | 1678:03fbf1b30e72 |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | 2 |
3 import de.intevation.flys.utils.DataUtil; | |
4 | |
3 import gnu.trove.TDoubleArrayList; | 5 import gnu.trove.TDoubleArrayList; |
4 | |
5 import java.util.Random; | |
6 | 6 |
7 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
8 | 8 |
9 public class WQ | 9 public class WQ |
10 extends NamedObjectImpl | 10 extends NamedObjectImpl |
115 public boolean guessWaterIncreasing() { | 115 public boolean guessWaterIncreasing() { |
116 return guessWaterIncreasing(0.05f); | 116 return guessWaterIncreasing(0.05f); |
117 } | 117 } |
118 | 118 |
119 public boolean guessWaterIncreasing(float factor) { | 119 public boolean guessWaterIncreasing(float factor) { |
120 | 120 return DataUtil.guessWaterIncreasing(w, factor); |
121 int N = w.size(); | |
122 if (N < 2) return false; | |
123 | |
124 int samples = (int)(factor*N) + 1; | |
125 | |
126 int up = 0; | |
127 | |
128 Random rand = new Random(); | |
129 | |
130 for (int i = 0; i < samples; ++i) { | |
131 int pos2 = rand.nextInt(N-1) + 1; | |
132 if (pos2 == 0) continue; | |
133 int pos1 = rand.nextInt(pos2); | |
134 double w1 = w.getQuick(pos1); | |
135 double w2 = w.getQuick(pos2); | |
136 if (w2 > w1) ++up; | |
137 } | |
138 | |
139 return up > samples/2; | |
140 } | 121 } |
141 | 122 |
142 public int [] longestIncreasingWRangeIndices() { | 123 public int [] longestIncreasingWRangeIndices() { |
143 return longestIncreasingWRangeIndices(new int[2]); | 124 return longestIncreasingWRangeIndices(new int[2]); |
144 } | 125 } |