changeset 3635:6342166ccdef

Fix issue774 (wrong items). flys-artifacts/trunk@5343 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Sun, 02 Sep 2012 08:44:23 +0000
parents 001e35349203
children 9f485f9fe8f9
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sat Sep 01 15:44:38 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sun Sep 02 08:44:23 2012 +0000
@@ -1,3 +1,10 @@
+2012-09-02	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Fix issue774 (wrong ranges for w/q input).
+
+	* src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java:
+	  Do not add items for gauges that do not intersect with given range.
+
 2012-09-01	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Fix issue829 (wrong fixation names).
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java	Sat Sep 01 15:44:38 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java	Sun Sep 02 08:44:23 2012 +0000
@@ -30,6 +30,7 @@
 
 
 /**
+ * State to input W/Q data.
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class WQAdapted extends DefaultState {
@@ -56,6 +57,7 @@
     public static final GaugeOrder GAUGE_UP   = new GaugeOrder(true);
     public static final GaugeOrder GAUGE_DOWN = new GaugeOrder(false);
 
+    /** Trivial, empty constructor. */
     public WQAdapted() {
     }
 
@@ -97,6 +99,7 @@
     }
 
 
+    /** Creates "Q" and "W" items. */
     protected Element[] createModeItems(
         XMLUtils.ElementCreator cr,
         Artifact    artifact,
@@ -134,7 +137,7 @@
             return null;
         }
 
-        Element[] elements = new Element[num];
+        List<Element> elements = new ArrayList<Element>();
 
         double rangeFrom = dist[0];
         double rangeTo   = dist[1];
@@ -148,14 +151,19 @@
                 double lower = range.getA().doubleValue();
                 double upper = range.getB().doubleValue();
 
+                // If gauge out of range, skip it.
+                if (upper <= rangeFrom || lower >= rangeTo) {
+                    continue;
+                }
+
                 double from = lower < rangeFrom ? rangeFrom : lower;
                 double to   = upper > rangeTo   ? rangeTo   : upper;
 
                 double[] mmQ = determineMinMaxQ(gauge, wst);
                 double[] mmW = gauge.determineMinMaxW();
 
-                elements[idx++] = createItem(
-                    cr, new String[] { from + ";" + to, ""}, mmQ, mmW);
+                elements.add(createItem(
+                    cr, new String[] { from + ";" + to, ""}, mmQ, mmW));
             }
         }
         else {
@@ -170,15 +178,18 @@
                 double from = lower < rangeFrom ? rangeFrom : lower;
                 double to   = upper > rangeTo   ? rangeTo   : upper;
 
+                // TODO probably need to continue out if oof range (see above).
+
                 double[] mmQ = determineMinMaxQ(gauge, wst);
                 double[] mmW = gauge.determineMinMaxW();
 
-                elements[idx++] = createItem(
-                    cr, new String[] { to + ";" + from, ""}, mmQ, mmW);
+                elements.add(createItem(
+                    cr, new String[] { to + ";" + from, ""}, mmQ, mmW));
             }
         }
 
-        return elements;
+        Element[] els = new Element[elements.size()];
+        return elements.toArray(els);
     }
 
 

http://dive4elements.wald.intevation.org