Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRange.java Thu Sep 12 18:43:21 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRange.java Thu Sep 12 18:58:19 2013 +0200 @@ -31,8 +31,30 @@ } public ImportRange(BigDecimal a, BigDecimal b) { - this.a = a; - this.b = b; + + // enforce a<b and set only a for zero-length ranges + if (a != null && b == null) { + this.a = a; + this.b = null; + } + else if (a == null && b != null) { + this.a = b; + this.b = null; + } + else if (a == null && b == null) { + throw new IllegalArgumentException("Both a and b are null."); + } + else if (a == b) { + this.a = a; + this.b = null; + } + else { + if (a.compareTo(b) == 1) { + BigDecimal t = a; a = b; b = t; + } + this.a = a; + this.b = b; + } } private static final int compare(BigDecimal a, BigDecimal b) { @@ -48,12 +70,6 @@ return a.compareTo(b); } - public void fixRangesOrder() { - if (compare(a, b) > 0) { - BigDecimal t = a; a = b; b = t; - } - } - public int compareTo(ImportRange other) { int cmp = compare(a, other.a); if (cmp != 0) return cmp;