changeset 1155:854c2f7da3f1

Fix flys/issue279 . flys-artifacts/trunk@2686 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 09 Sep 2011 13:02:23 +0000
parents 24b87650136f
children 4da9f058fed6
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java
diffstat 2 files changed, 37 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Sep 09 12:37:52 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Sep 09 13:02:23 2011 +0000
@@ -1,3 +1,10 @@
+2011-09-09  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+ Fix flys/issue279 .
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Fix behaviour in various thinkable malconditions.
+
 2011-09-09  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Sep 09 12:37:52 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Sep 09 13:02:23 2011 +0000
@@ -74,11 +74,9 @@
     /** The logger for this class. */
     private static Logger logger = Logger.getLogger(WINFOArtifact.class);
 
-
     /** The name of the artifact. */
     public static final String ARTIFACT_NAME = "winfo";
 
-
     /** XPath */
     public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
 
@@ -651,7 +649,12 @@
      * @return list of points of CrossSectionLine, sorted.
      */
     protected List<Point2D> getCrossSectionLinesPoints(CrossSectionLine line) {
-        List<Point2D> points = new ArrayList<Point2D>(); 
+        List<Point2D> points = new ArrayList<Point2D>();
+
+        if (line == null) {
+            return points;
+        }
+
         List<CrossSectionPoint> linePoints = line.getPoints();
         if (linePoints.isEmpty()) {
             logger.info("No points in selected CrossSectionLine.");
@@ -686,8 +689,12 @@
 
         // Get the cross section closest to requested km.
         // Naive, linear approach.
+        List<CrossSection> sections = getCrossSections();
+        if (sections.size() == 0 || sections.get(0).getLines().size() == 0) {
+            return null;
+        }
         List<CrossSectionLine> crossSectionLines =
-            getCrossSections().get(0).getLines();
+            sections.get(0).getLines();
         CrossSectionLine oldLine = crossSectionLines.get(0);
         double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue());
         for (CrossSectionLine line: crossSectionLines) {
@@ -710,7 +717,14 @@
      */
     public double getCrossSectionSnapKm() {
         // Note that this is this triggers a linear search.
-        return searchCrossSectionKmLine().getKm().doubleValue();
+        CrossSectionLine line = searchCrossSectionKmLine();
+        if (line == null) {
+            logger.warn("No Cross Section for given km found.");
+            return 0.0f;
+        }
+        else {
+            return line.getKm().doubleValue();
+        }
     }
 
 
@@ -761,19 +775,24 @@
                 ;
             }
 
+            if (triple.size() == 0) {
+                logger.warn("Calculation of waterline is empty.");
+                return CrossSectionApp.createWaterLines(points, 0.0f);
+            }
+
             // Linear seach in WQKms for closest km.
             double old_dist_wish = Math.abs(wishKM - triple.getKm(0));
+            double last_w = triple.getW(0);
 
             for (int i = 0; i < triple.size(); i++) {
                 double diff = Math.abs(wishKM - triple.getKm(i));
                 if (diff > old_dist_wish) {
-                    return CrossSectionApp.createWaterLines(points,
-                        triple.getW(i));
+                    break;
                 }
+                last_w = triple.getW(i);
                 old_dist_wish = diff;
             }
-            return CrossSectionApp.createWaterLines(points,
-                triple.getW(triple.size()-1));
+            return CrossSectionApp.createWaterLines(points, last_w);
         }
     }
 
@@ -795,6 +814,8 @@
 
     /**
      * Get points of CrossSection Line.
+     * @param csl The crossSectionline of interest.
+     * @return x and y positions of cross section profile.
      */
     protected double [][] getCrossSectionProfile(CrossSectionLine csl) {
         List<Point2D> points = getCrossSectionLinesPoints(csl);

http://dive4elements.wald.intevation.org