diff 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
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Thu Oct 04 14:12:03 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Thu Oct 04 14:54:44 2012 +0200
@@ -265,9 +265,19 @@
     public static double getWAtKmLin(WKms wkms, double km) {
         // Uninformed search.
         int size = wkms.size();
+        if (size == 0) {
+            return -1;
+        }
         int idx = 0;
-        boolean kmIncreasing = (wkms.getKm(0) < wkms.getKm(wkms.size()-1))
-            ? true : false;
+
+        boolean kmIncreasing;
+        if (size == 1) {
+            kmIncreasing = true;
+        }
+        else {
+            kmIncreasing = (wkms.getKm(0) < wkms.getKm(wkms.size()-1))
+                ? true : false;
+        }
         if (kmIncreasing) {
             while (idx < size && wkms.getKm(idx) < km) {
                 idx++;
@@ -280,6 +290,10 @@
             }
         }
 
+       if (wkms.getKm(idx) == km) {
+           return wkms.getW(idx);
+       }
+
         if (idx == size -1 || idx == 0) {
             return -1;
         }

http://dive4elements.wald.intevation.org