Mercurial > dive4elements > river
changeset 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 (2013-09-12) |
parents | 0850a4983fcd |
children | bb5bd48b80f6 |
files | backend/src/main/java/org/dive4elements/river/importer/ImportRange.java backend/src/main/java/org/dive4elements/river/importer/ImportWst.java backend/src/main/java/org/dive4elements/river/importer/ImportWstColumn.java backend/src/main/java/org/dive4elements/river/importer/ImportWstColumnQRange.java backend/src/main/java/org/dive4elements/river/importer/ImportWstQRange.java backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java |
diffstat | 6 files changed, 24 insertions(+), 32 deletions(-) [+] |
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;
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportWst.java Thu Sep 12 18:43:21 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportWst.java Thu Sep 12 18:58:19 2013 +0200 @@ -130,11 +130,6 @@ session.flush(); } - public void fixRangesOrder() { - for (ImportWstColumn column: columns) { - column.fixRangesOrder(); - } - } /** Get corresponding mapped wst (from database). */ public Wst getPeer(River river) {
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportWstColumn.java Thu Sep 12 18:43:21 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportWstColumn.java Thu Sep 12 18:58:19 2013 +0200 @@ -181,10 +181,5 @@ return peer; } - public void fixRangesOrder() { - for (ImportWstColumnQRange wcqr: columnQRanges) { - wcqr.fixRangesOrder(); - } - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportWstColumnQRange.java Thu Sep 12 18:43:21 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportWstColumnQRange.java Thu Sep 12 18:58:19 2013 +0200 @@ -52,10 +52,6 @@ this.qRange = qRange; } - public void fixRangesOrder() { - qRange.fixRangesOrder(); - } - public WstColumnQRange getPeer(River river) { if (peer == null) { WstColumn c = wstColumn.getPeer(river);
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportWstQRange.java Thu Sep 12 18:43:21 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportWstQRange.java Thu Sep 12 18:58:19 2013 +0200 @@ -62,10 +62,6 @@ this.q = q; } - public void fixRangesOrder() { - range.fixRangesOrder(); - } - public WstQRange getPeer(River river) { if (peer == null) { Range r = range.getPeer(river);
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java Thu Sep 12 18:43:21 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java Thu Sep 12 18:58:19 2013 +0200 @@ -385,18 +385,12 @@ BigDecimal t = minKm; minKm = maxKm; maxKm = t; } addInterval(minKm, maxKm, aktAbfluesse); - - fixRangesOrder(); } finally { in.close(); } } - protected void fixRangesOrder() { - wst.fixRangesOrder(); - } - protected void addValue(BigDecimal km, BigDecimal w, int index) { if (w != null) { ImportWstColumn column = wst.getColumn(index);