[PATCH] Trying to avoid symptoms of == double comparison
Wald Commits
scm-commit at wald.intevation.org
Tue Mar 6 17:04:21 CET 2018
# HG changeset patch
# User gernotbelger
# Date 1520352257 -3600
# Node ID b10f8415798c9fdecbab1c53389e0c11a805a91a
# Parent f972e1da4a633c69ba18a856a0c2892fa1b07151
Trying to avoid symptoms of == double comparison
diff -r f972e1da4a63 -r b10f8415798c artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java Tue Mar 06 17:02:45 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java Tue Mar 06 17:04:17 2018 +0100
@@ -17,12 +17,17 @@
import org.dive4elements.river.artifacts.model.WQKms;
import org.dive4elements.river.utils.DoubleUtil;
+import gnu.trove.TDoubleDoubleHashMap;
+
/**
* @author Gernot Belger
*/
public final class DischargeValuesFinder {
private final UnivariateRealFunction qInterpolator;
+
+ private final TDoubleDoubleHashMap exactValues;
+
private final QKms qKms;
/**
@@ -42,6 +47,14 @@
public DischargeValuesFinder(final QKms qKms) {
this.qKms = qKms;
this.qInterpolator = qKms == null ? null : DoubleUtil.getLinearInterpolator(qKms.allKms(), qKms.allQs());
+
+ this.exactValues = new TDoubleDoubleHashMap(qKms.size());
+
+ for (int i = 0; i < qKms.size(); i++) {
+ final double station = qKms.getKm(i);
+ final double discharge = qKms.getQ(i);
+ this.exactValues.put(station, discharge);
+ }
}
/**
@@ -56,6 +69,13 @@
}
public double getDischarge(final double station) throws FunctionEvaluationException {
+
+ // IMPORTANT: we first try to retreive the exact value if it is present, to avoid rounding changes due to interpolation.
+ // This is important because in the WaterlevelExporter code, these values are double-compared (with '==' ...) in order
+ // to find the corresponding main-value.
+ if (this.exactValues.contains(station))
+ return this.exactValues.get(station);
+
return this.qInterpolator.value(station);
}
}
\ No newline at end of file
More information about the Dive4Elements-commits
mailing list