Mercurial > dive4elements > river
changeset 5878:a7b56219b362
Partial fix for flys/issue1247: When trying to find gauges take care of the fact that start and end position are in abitrary order.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 29 Apr 2013 15:54:17 +0200 |
parents | a251ccee56e4 |
children | 895b80728095 |
files | backend/src/main/java/org/dive4elements/river/model/River.java |
diffstat | 1 files changed, 22 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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();