comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java @ 4031:e4e345d81a65

issue889/2
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 04 Oct 2012 14:54:44 +0200
parents f68d6dcaea94
children 58864f4f6e3b
comparison
equal deleted inserted replaced
4030:4bc58d6ee9db 4031:e4e345d81a65
263 * Returns -1 if not found. 263 * Returns -1 if not found.
264 */ 264 */
265 public static double getWAtKmLin(WKms wkms, double km) { 265 public static double getWAtKmLin(WKms wkms, double km) {
266 // Uninformed search. 266 // Uninformed search.
267 int size = wkms.size(); 267 int size = wkms.size();
268 if (size == 0) {
269 return -1;
270 }
268 int idx = 0; 271 int idx = 0;
269 boolean kmIncreasing = (wkms.getKm(0) < wkms.getKm(wkms.size()-1)) 272
270 ? true : false; 273 boolean kmIncreasing;
274 if (size == 1) {
275 kmIncreasing = true;
276 }
277 else {
278 kmIncreasing = (wkms.getKm(0) < wkms.getKm(wkms.size()-1))
279 ? true : false;
280 }
271 if (kmIncreasing) { 281 if (kmIncreasing) {
272 while (idx < size && wkms.getKm(idx) < km) { 282 while (idx < size && wkms.getKm(idx) < km) {
273 idx++; 283 idx++;
274 } 284 }
275 } 285 }
277 idx = wkms.size() -1; 287 idx = wkms.size() -1;
278 while (idx > 0 && wkms.getKm(idx) > km) { 288 while (idx > 0 && wkms.getKm(idx) > km) {
279 idx--; 289 idx--;
280 } 290 }
281 } 291 }
292
293 if (wkms.getKm(idx) == km) {
294 return wkms.getW(idx);
295 }
282 296
283 if (idx == size -1 || idx == 0) { 297 if (idx == size -1 || idx == 0) {
284 return -1; 298 return -1;
285 } 299 }
286 300

http://dive4elements.wald.intevation.org