Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ValueKey.java @ 503:bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
flys-backend/trunk@1859 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 09 May 2011 10:04:23 +0000 |
parents | 04d449f7f0c9 |
children | 6dc847194625 |
comparison
equal
deleted
inserted
replaced
502:c6889097f81f | 503:bcc18293a547 |
---|---|
1 package de.intevation.flys.importer; | 1 package de.intevation.flys.importer; |
2 | 2 |
3 import java.math.BigDecimal; | 3 import java.math.BigDecimal; |
4 | 4 |
5 import java.util.Comparator; | |
6 | |
5 public class ValueKey | 7 public class ValueKey |
6 { | 8 { |
9 public static final double EPSILON = 1e-6; | |
10 | |
11 public static final Comparator<ValueKey> EPSILON_COMPARATOR = | |
12 new Comparator<ValueKey>() | |
13 { | |
14 public int compare(ValueKey x, ValueKey y) { | |
15 int cmp = ValueKey.compare(x.a, y.a); | |
16 if (cmp != 0) return cmp; | |
17 return ValueKey.compare(x.b, y.b); | |
18 } | |
19 }; | |
20 | |
21 public static int compare(BigDecimal a, BigDecimal b) { | |
22 if (a == null && b == null) return 0; | |
23 if (a != null && b == null) return +1; | |
24 if (a == null && b != null) return -1; | |
25 | |
26 double diff = a.doubleValue() - b.doubleValue(); | |
27 if (diff < -EPSILON) return -1; | |
28 return diff > EPSILON ? +1 : 0; | |
29 } | |
30 | |
7 protected BigDecimal a; | 31 protected BigDecimal a; |
8 protected BigDecimal b; | 32 protected BigDecimal b; |
9 | 33 |
10 public ValueKey() { | 34 public ValueKey() { |
11 } | 35 } |