annotate flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java @ 4741:f6d0ad25f1ee

Merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 02 Jan 2013 15:42:22 +0100
parents 94b39073f0f7
children
rev   line source
4735
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@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
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
5 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
6 {
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 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
8
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 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
10
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 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
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 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
14 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
15 }
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
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 @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
18 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
19 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
20 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
21 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
22 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
23 }
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 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org