annotate flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java @ 5263:db341e37d194

ImportWst: Doc and getters.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 13 Mar 2013 10:05:47 +0100
parents ce6b9945bf8e
children
rev   line source
4742
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4732
diff changeset
1 package de.intevation.flys.utils;
4732
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.Comparator;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
4742
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4732
diff changeset
5 /** Comparator with some tolerance (epsilon). */
4732
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 public class EpsilonComparator implements Comparator<Double>
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 {
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 public static final double EPSILON = 1e-4;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
4742
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4732
diff changeset
10 /** Ready-made comparator with 1e-4 tolerance. */
4732
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON);
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 private double epsilon;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 public EpsilonComparator(double epsilon) {
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 this.epsilon = epsilon;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 }
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 @Override
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public int compare(Double a, Double b) {
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 double diff = a - b;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 if (diff < -epsilon) return -1;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 if (diff > epsilon) return +1;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 return 0;
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 }
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 }
7fdddc6ba296 Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org