[PATCH] Fixed: filtering of gauge list did not handle cases correctly, where fromKm > toKm
Wald Commits
scm-commit at wald.intevation.org
Fri Jul 20 16:03:47 CEST 2018
# HG changeset patch
# User gernotbelger
# Date 1532095420 -7200
# Node ID 486b6160962fae72e3b6a0a2607d5053c12b7551
# Parent 55e2155ab52d8d59a5e142236c7a444fd9cb812e
Fixed: filtering of gauge list did not handle cases correctly, where fromKm > toKm
diff -r 55e2155ab52d -r 486b6160962f gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java
--- 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);
- }
}
}
More information about the Dive4Elements-commits
mailing list