# HG changeset patch # User Felix Wolfsteller # Date 1315573343 0 # Node ID 854c2f7da3f110d524707dcc16695b31df03454d # Parent 24b87650136f2e159914473a37e656f63853cb7c Fix flys/issue279 . flys-artifacts/trunk@2686 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 24b87650136f -r 854c2f7da3f1 flys-artifacts/ChangeLog --- 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 + + Fix flys/issue279 . + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + Fix behaviour in various thinkable malconditions. + 2011-09-09 Felix Wolfsteller * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: diff -r 24b87650136f -r 854c2f7da3f1 flys-artifacts/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 getCrossSectionLinesPoints(CrossSectionLine line) { - List points = new ArrayList(); + List points = new ArrayList(); + + if (line == null) { + return points; + } + List 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 sections = getCrossSections(); + if (sections.size() == 0 || sections.get(0).getLines().size() == 0) { + return null; + } List 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 points = getCrossSectionLinesPoints(csl);