comparison backend/src/main/java/org/dive4elements/river/importer/ImportRange.java @ 7003:3d83a4cf33ba double-precision

Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
author Tom Gottfried <tom.gottfried@intevation.de>
date Thu, 12 Sep 2013 18:58:19 +0200
parents 4c3ccf2b0304
children 70ab9e8cdefb
comparison
equal deleted inserted replaced
7002:0850a4983fcd 7003:3d83a4cf33ba
29 29
30 public ImportRange() { 30 public ImportRange() {
31 } 31 }
32 32
33 public ImportRange(BigDecimal a, BigDecimal b) { 33 public ImportRange(BigDecimal a, BigDecimal b) {
34 this.a = a; 34
35 this.b = b; 35 // enforce a<b and set only a for zero-length ranges
36 if (a != null && b == null) {
37 this.a = a;
38 this.b = null;
39 }
40 else if (a == null && b != null) {
41 this.a = b;
42 this.b = null;
43 }
44 else if (a == null && b == null) {
45 throw new IllegalArgumentException("Both a and b are null.");
46 }
47 else if (a == b) {
48 this.a = a;
49 this.b = null;
50 }
51 else {
52 if (a.compareTo(b) == 1) {
53 BigDecimal t = a; a = b; b = t;
54 }
55 this.a = a;
56 this.b = b;
57 }
36 } 58 }
37 59
38 private static final int compare(BigDecimal a, BigDecimal b) { 60 private static final int compare(BigDecimal a, BigDecimal b) {
39 if (a == null && b == null) { 61 if (a == null && b == null) {
40 return 0; 62 return 0;
44 } 66 }
45 if (a != null && b == null) { 67 if (a != null && b == null) {
46 return +1; 68 return +1;
47 } 69 }
48 return a.compareTo(b); 70 return a.compareTo(b);
49 }
50
51 public void fixRangesOrder() {
52 if (compare(a, b) > 0) {
53 BigDecimal t = a; a = b; b = t;
54 }
55 } 71 }
56 72
57 public int compareTo(ImportRange other) { 73 public int compareTo(ImportRange other) {
58 int cmp = compare(a, other.a); 74 int cmp = compare(a, other.a);
59 if (cmp != 0) return cmp; 75 if (cmp != 0) return cmp;

http://dive4elements.wald.intevation.org