changeset 4031:e4e345d81a65

issue889/2
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 04 Oct 2012 14:54:44 +0200
parents 4bc58d6ee9db
children a5e1ca620f15
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java
diffstat 2 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Oct 04 14:12:03 2012 +0200
+++ b/flys-artifacts/ChangeLog	Thu Oct 04 14:54:44 2012 +0200
@@ -1,3 +1,10 @@
+2012-10-04	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Fix issue889/2 .
+
+	* flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java:
+	  Do not AIOOB on wsts with one (or zero) value only.
+
 2012-10-04	Björn Ricks	<bjoern.ricks@intevation.de>
 
 	* src/main/resources/messages.properties,
@@ -21,8 +28,10 @@
 	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
 	  Avoid NullPointerException if not attribute outs are present.
 
-2012-10-03	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+2012-10-04	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
 	Fix issue417.
+
 	* flys-artifacts/doc/conf/default-themes,
 	  flys-artifacts/doc/conf/second-themes,
 	  flys-artifacts/doc/conf/virtual-themes:
--- 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