Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java @ 4834:601f9d69cc10
insert helpText links
author | Bettina Gruenbauer <bettina@intevation.de> |
---|---|
date | Tue, 22 Jan 2013 15:13:58 +0100 |
parents | ce6b9945bf8e |
children |
rev | line source |
---|---|
4742 | 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 | 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 | 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 : |