diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 649:44175d4720f8

Fix crashes in back jump correction. flys-artifacts/trunk@2038 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 01 Jun 2011 09:57:22 +0000
parents 433f67a076aa
children 913b52064449
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 01 09:18:00 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 01 09:57:22 2011 +0000
@@ -535,6 +535,38 @@
 
     }
 
+    protected static double [] extractBoundsKm(River river, double [][] segments) {
+
+        if (segments.length == 2) {
+            return getBounds(segments);
+        }
+
+        TDoubleArrayList bounds = new TDoubleArrayList();
+
+        bounds.add(Math.min(segments[0][0], segments[0][1]));
+
+        for (int i = 1; i < segments.length-1; ++i) {
+            double [] segment = segments[i];
+
+            Gauge gauge = river.determineGauge(segment[0], segment[1]);
+
+            if (gauge == null) {
+                logger.warn("no gauge found between " + 
+                    segment[0] + " and " + segment[1]);
+                bounds.add(0.5*(segment[0] + segment[1]));
+            }
+            else {
+                bounds.add(gauge.getStation().doubleValue());
+            }
+        }
+
+        bounds.add(Math.max(
+            segments[segments.length-1][0],
+            segments[segments.length-1][1]));
+
+        return bounds.toNativeArray();
+    }
+
     /**
      * Returns the data computed by the discharge longitudinal section
      * computation.
@@ -594,37 +626,8 @@
 
         // more than one segment
 
-        double [] boundKms;
-
-        if (segments.length == 2) {
-            boundKms = getBounds(segments);
-        }
-        else {
-            TDoubleArrayList bounds = new TDoubleArrayList();
-
-            bounds.add(Math.min(segments[0][0], segments[0][1]));
-
-            for (int i = 1; i < segments.length-1; ++i) {
-                double [] segment = segments[i];
-
-                Gauge gauge = river.determineGauge(segment[0], segment[1]);
+        double [] boundKms = extractBoundsKm(river, segments);
 
-                if (gauge == null) {
-                    logger.warn("no gauge found between " + 
-                        segment[0] + " and " + segment[1]);
-                    bounds.add(0.5*(segment[0] + segment[1]));
-                }
-                else {
-                    bounds.add(gauge.getStation().doubleValue());
-                }
-            }
-
-            bounds.add(Math.max(
-                segments[segments.length-1][0],
-                segments[segments.length-1][1]));
-
-            boundKms = bounds.toNativeArray();
-        }
 
         if (logger.isDebugEnabled()) {
             logger.debug("bound kms: " + joinDoubles(boundKms));

http://dive4elements.wald.intevation.org