comparison 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
comparison
equal deleted inserted replaced
3010:05a3fe8800b3 3011:ab81ffd1343e
1 package de.intevation.flys.utils;
2
3 import java.io.Serializable;
4
5 import java.util.Comparator;
6
7 public class EpsilonComparator
8 implements Serializable, Comparator<Double>
9 {
10 public static final double EPSILON = 1e-5;
11
12 public static final EpsilonComparator INSTANCE =
13 new EpsilonComparator(EPSILON);
14
15 protected double epsilon;
16
17 public EpsilonComparator() {
18 this(EPSILON);
19 }
20
21 public EpsilonComparator(double epsilon) {
22 this.epsilon = Math.abs(epsilon);
23 }
24
25 private static final double value(Double x) {
26 return x != null ? x.doubleValue() : 0.0;
27 }
28
29 @Override
30 public int compare(Double a, Double b) {
31 double diff = value(a) - value(b);
32 if (diff < epsilon) return -1;
33 return diff > epsilon ? +1 : 0;
34 }
35 }
36 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org