comparison backend/src/main/java/org/dive4elements/river/backend/utils/EpsilonComparator.java @ 8187:3bb1c62ad732

Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 04 Sep 2014 15:03:25 +0200
parents backend/src/main/java/org/dive4elements/river/utils/EpsilonComparator.java@164e2f2c9bea
children
comparison
equal deleted inserted replaced
8186:a1ceacf15d3a 8187:3bb1c62ad732
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.backend.utils;
10
11 import java.util.Comparator;
12 import java.io.Serializable;
13
14 /** Comparator with some tolerance (epsilon). */
15 public class EpsilonComparator implements Comparator<Double>, Serializable
16 {
17 public static final double EPSILON = 1e-4;
18
19 /** Ready-made comparator with 1e-4 tolerance. */
20 public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON);
21
22 private double epsilon;
23
24 public EpsilonComparator(double epsilon) {
25 this.epsilon = epsilon;
26 }
27
28 @Override
29 public int compare(Double a, Double b) {
30 double diff = a - b;
31 if (diff < -epsilon) return -1;
32 if (diff > epsilon) return +1;
33 return 0;
34 }
35 }
36 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org