[PATCH] Range import: enforce a<b not only for WSTs and set only a for zero-length ranges

Wald Commits scm-commit at wald.intevation.org
Thu Sep 12 18:58:25 CEST 2013


# HG changeset patch
# User Tom Gottfried <tom.gottfried at intevation.de>
# Date 1379005099 -7200
# Branch double-precision
# Node ID 3d83a4cf33badfee252ed1a1bace96c5d76dc81b
# Parent  0850a4983fcd0aa336432eced212bf3dfeb162e5
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.

diff -r 0850a4983fcd -r 3d83a4cf33ba backend/src/main/java/org/dive4elements/river/importer/ImportRange.java
--- 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;
diff -r 0850a4983fcd -r 3d83a4cf33ba backend/src/main/java/org/dive4elements/river/importer/ImportWst.java
--- 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) {
diff -r 0850a4983fcd -r 3d83a4cf33ba backend/src/main/java/org/dive4elements/river/importer/ImportWstColumn.java
--- 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 :
diff -r 0850a4983fcd -r 3d83a4cf33ba backend/src/main/java/org/dive4elements/river/importer/ImportWstColumnQRange.java
--- 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);
diff -r 0850a4983fcd -r 3d83a4cf33ba backend/src/main/java/org/dive4elements/river/importer/ImportWstQRange.java
--- 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);
diff -r 0850a4983fcd -r 3d83a4cf33ba backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
--- 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);


More information about the Dive4elements-commits mailing list