Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 1033:821aaceb2776
Fix for flys/issue191
flys-artifacts/trunk@2494 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 15 Aug 2011 10:56:58 +0000 |
parents | 659608128823 |
children | 03fbf1b30e72 |
comparison
equal
deleted
inserted
replaced
1032:abd2ab6dff4f | 1033:821aaceb2776 |
---|---|
2 | 2 |
3 import gnu.trove.TDoubleArrayList; | 3 import gnu.trove.TDoubleArrayList; |
4 | 4 |
5 import java.util.Random; | 5 import java.util.Random; |
6 | 6 |
7 import org.apache.log4j.Logger; | |
8 | |
7 public class WQ | 9 public class WQ |
8 extends NamedObjectImpl | 10 extends NamedObjectImpl |
9 { | 11 { |
12 private static Logger logger = Logger.getLogger(WQ.class); | |
13 | |
10 // TODO: s/w/ws/g | 14 // TODO: s/w/ws/g |
11 protected TDoubleArrayList w; | 15 protected TDoubleArrayList w; |
12 | 16 |
13 // TODO: s/q/qs/g | 17 // TODO: s/q/qs/g |
14 protected TDoubleArrayList q; | 18 protected TDoubleArrayList q; |
133 } | 137 } |
134 | 138 |
135 return up > samples/2; | 139 return up > samples/2; |
136 } | 140 } |
137 | 141 |
142 public int [] longestIncreasingWRangeIndices() { | |
143 return longestIncreasingWRangeIndices(new int[2]); | |
144 } | |
145 | |
146 public int [] longestIncreasingWRangeIndices(int [] bounds) { | |
147 | |
148 int N = size(); | |
149 int start = 0; | |
150 int stop = 0; | |
151 | |
152 double lastW = Double.MAX_VALUE; | |
153 | |
154 for (int i = 0; i < N; ++i) { | |
155 double v = w.getQuick(i); | |
156 if (v <= lastW) { | |
157 if (stop-start > bounds[1]-bounds[0]) { | |
158 bounds[0] = start; | |
159 bounds[1] = stop; | |
160 if (logger.isDebugEnabled()) { | |
161 logger.debug("new range: " + | |
162 bounds[0] + " - " + bounds[1] + " (" + | |
163 w.getQuick(bounds[0]) + ", " + | |
164 w.getQuick(bounds[1]) + ")"); | |
165 | |
166 } | |
167 } | |
168 start = stop = i; | |
169 } | |
170 else { | |
171 stop = i; | |
172 } | |
173 lastW = v; | |
174 } | |
175 | |
176 if (stop-start > bounds[1]-bounds[0]) { | |
177 bounds[0] = start; | |
178 bounds[1] = stop; | |
179 if (logger.isDebugEnabled()) { | |
180 logger.debug("new range @end: " + | |
181 bounds[0] + " - " + bounds[1] + " (" + | |
182 w.getQuick(bounds[0]) + ", " + | |
183 w.getQuick(bounds[1]) + ")"); | |
184 | |
185 } | |
186 } | |
187 | |
188 return bounds; | |
189 } | |
138 } | 190 } |
139 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 191 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |