diff flys-artifacts/src/main/java/de/intevation/flys/utils/EpsilonComparator.java @ 3011:ab81ffd1343e

FixA: Reactivated rewrite of the outlier checks. flys-artifacts/trunk@4576 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 04 Jun 2012 16:44:56 +0000
parents
children 0330bff1b382
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/EpsilonComparator.java	Mon Jun 04 16:44:56 2012 +0000
@@ -0,0 +1,36 @@
+package de.intevation.flys.utils;
+
+import java.io.Serializable;
+
+import java.util.Comparator;
+
+public class EpsilonComparator
+implements   Serializable, Comparator<Double>
+{
+    public static final double EPSILON = 1e-5;
+
+    public static final EpsilonComparator INSTANCE =
+        new EpsilonComparator(EPSILON);
+
+    protected double epsilon;
+
+    public EpsilonComparator() {
+        this(EPSILON);
+    }
+
+    public EpsilonComparator(double epsilon) {
+        this.epsilon = Math.abs(epsilon);
+    }
+
+    private static final double value(Double x) {
+        return x != null ? x.doubleValue() : 0.0;
+    }
+
+    @Override
+    public int compare(Double a, Double b) {
+        double diff = value(a) - value(b);
+        if (diff < epsilon) return -1;
+        return diff > epsilon ? +1 : 0;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org