[Dive4elements-commits] [PATCH 1 of 2] Partial fix for flys/issue1247: When trying to find gauges take care of the fact that start and end position are in abitrary order

Wald Commits scm-commit at wald.intevation.org
Mon Apr 29 16:04:20 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1367243657 -7200
# Node ID a7b56219b362aea7162bb8c17457868fa5e161c5
# Parent  a251ccee56e4fba7b0b458f157da87f0d88dedcd
Partial fix for flys/issue1247: When trying to find gauges take care of the fact that start and end position are in abitrary order.

diff -r a251ccee56e4 -r a7b56219b362 backend/src/main/java/org/dive4elements/river/model/River.java
--- a/backend/src/main/java/org/dive4elements/river/model/River.java	Mon Apr 29 11:42:15 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/River.java	Mon Apr 29 15:54:17 2013 +0200
@@ -200,6 +200,8 @@
             double c = r.getA().doubleValue();
             double d = r.getB().doubleValue();
 
+            if (c > d) { double t = c; c = d; d = t; }
+
             double start = c >= a ? c : a;
             double stop  = d <= b ? d : b;
 
@@ -228,7 +230,9 @@
         Session session = SessionHolder.HOLDER.get();
         Query query = session.createQuery(
             "from Gauge g where river=:river "  +
-            "and :p between g.range.a and g.range.b");
+            "and :p between " + 
+            "least(g.range.a, g.range.b) and " +
+            "greatest(g.range.a, g.range.b)");
         query.setParameter("river", this);
         query.setParameter("p", new BigDecimal(p, PRECISION));
         List<Gauge> gauges = query.list();
@@ -265,7 +269,7 @@
 
         query.setParameter("river", getId());
 
-        double minmax[] = new double[] { Double.MAX_VALUE, Double.MIN_VALUE };
+        double minmax[] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
 
         List<Object> results = query.list();
 
@@ -312,7 +316,7 @@
             return null;
         }
 
-        double minmax[] = new double[] { Double.MAX_VALUE, Double.MIN_VALUE };
+        double minmax[] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
 
         for (Gauge g: gauges) {
             Range r = g.getRange();
@@ -321,13 +325,23 @@
                 continue;
             }
 
-            double a  = r.getA().doubleValue();
-            minmax[0] = minmax[0] < a ? minmax[0] : a;
+            double a = r.getA().doubleValue();
+            if (a < minmax[0]) {
+                minmax[0] = a;
+            }
+            if (a > minmax[1]) {
+                minmax[1] = a;
+            }
 
             BigDecimal bigB = r.getB();
             if (bigB != null) {
-                double b  = bigB.doubleValue();
-                minmax[1] = minmax[1] > b ? minmax[1] : b;
+                double b = bigB.doubleValue();
+                if (b < minmax[0]) {
+                    minmax[0] = b;
+                }
+                if (b > minmax[1]) {
+                    minmax[1] = b;
+                }
             }
         }
 
@@ -336,7 +350,7 @@
 
     public Map<Double, Double> queryGaugeDatumsKMs() {
         List<Gauge> gauges = getGauges();
-        Map result = new TreeMap<Double, Double>(KM_CMP);
+        Map<Double, Double> result = new TreeMap<Double, Double>(KM_CMP);
 
         for (Gauge gauge: gauges) {
             BigDecimal km    = gauge.getStation();


More information about the Dive4elements-commits mailing list