changeset 9284:486b6160962f

Fixed: filtering of gauge list did not handle cases correctly, where fromKm > toKm
author gernotbelger
date Fri, 20 Jul 2018 16:03:40 +0200
parents 55e2155ab52d
children 9b16f58c62a7
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java
diffstat 1 files changed, 24 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java	Fri Jul 20 15:24:05 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java	Fri Jul 20 16:03:40 2018 +0200
@@ -290,33 +290,37 @@
         }
     }
 
-    public void openOnDistance(final Double start, final Double end, final DisappearType type) {
+    public void openOnDistance(final double start, final Double end, final DisappearType type) {
         GWT.log("GaugeListGrid - openOnDistance " + start + " " + end);
 
         setData(new ListGridRecord[] {});
 
+        double to = end == null ? Double.MAX_VALUE: end;
+
+        double from = Math.min(start, to);
+        to = Math.max(start, to);
+        
         for (final GaugeInfo gauge : this.gauges) {
 
-            if (end == null && gauge.getKmStart() != null) {
-                if (gauge.getKmStart() >= start) {
-                    addExpandedRecord(gauge);
-                } else {
-                    removeOrCollapse(gauge, type);
-                }
-            } else if (gauge.getKmStart() != null && gauge.getKmEnd() != null) {
-                // as getStart()/getEnd() return Double objects,
-                // they can be null and
-                // can cause NPEs when comparing with double... strange...
-                GWT.log("GaugeListGrid - openOnDistance item " + gauge.getKmStart() + " " + gauge.getKmEnd());
-                if ((start >= gauge.getKmStart() && start <= gauge.getKmEnd()) || (end >= gauge.getKmStart() && end <= gauge.getKmEnd())
-                        || (start <= gauge.getKmStart() && end >= gauge.getKmEnd())) {
-                    addExpandedRecord(gauge);
-                } else {
-                    removeOrCollapse(gauge, type);
-                }
-            } else {
+            /* in earlier version, it was assumed that gaugeEnd may be null, but start not. */
+            final Double gaugeStart = gauge.getKmStart();
+            final Double gaugeEnd = gauge.getKmEnd() == null ? gaugeStart : gauge.getKmEnd();
+            
+            boolean expand;
+            if( gaugeStart == null )
+                expand = false;
+            else {
+                
+                final double gaugeFrom = Math.min(gaugeStart, gaugeEnd);
+                final double gaugeTo = Math.max(gaugeStart, gaugeEnd);
+                
+                expand = (from >= gaugeFrom && from <= gaugeTo) || (to >= gaugeFrom && to <= gaugeTo) || (from <= gaugeFrom && to >= gaugeEnd);
+            }
+
+            if( expand )
+                addExpandedRecord(gauge);
+            else
                 removeOrCollapse(gauge, type);
-            }
         }
     }
 

http://dive4elements.wald.intevation.org