[PATCH 2 of 4] Modification of the range adding fixed

Wald Commits scm-commit at wald.intevation.org
Mon Apr 9 09:08:49 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1523203715 -7200
# Node ID 5ff8ce9a2e0612a19e070853d4156075d32820f5
# Parent  392bbcd8a88b952a5ada97cf04d4da12fba91798
Modification of the range adding fixed

diff -r 392bbcd8a88b -r 5ff8ce9a2e06 backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Sun Apr 08 18:07:06 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Sun Apr 08 18:08:35 2018 +0200
@@ -63,6 +63,8 @@
     protected ImportWst wst;
 
     protected ImportRange lastRange;
+    protected Double lastA;
+    protected Double lastB;
 
     public WstParser() {
     }
@@ -450,9 +452,8 @@
 
     protected void addInterval(
             final BigDecimal from,
-            final BigDecimal to,
-            final BigDecimal[] values
-            ) {
+            BigDecimal to,
+            final BigDecimal[] values) {
         log.debug("addInterval: " + from + " " + to);
 
         if (values == null || from == MAX_RANGE || from == MIN_RANGE) {
@@ -460,28 +461,38 @@
         }
 
         // expand single-line i.e. 0-lenght Q-range to minimal length
+        if (from == to) {
+            if (this.lastRange != null && this.lastA > this.lastB) {
+                to = from.subtract(INTERVAL_GAP);
+            }
+            else {
+                to = from.add(INTERVAL_GAP);
+            }
+        }
+
         final ImportRange range = new ImportRange(from, to);
-        if (from == to) {
-            if ((this.lastRange != null) && (this.lastRange.difference() < 0.0))
-                range.setB(from.subtract(INTERVAL_GAP));
-            else
-                range.setB(from.add(INTERVAL_GAP));
-        }
 
         // little workaround to make the q ranges tightly fit.
         // Leave a very small gap to ensure that the range queries
         // still work.
 
         if (this.lastRange != null) {
-            if (this.lastRange.difference() > 0.0)
+            if (this.lastA < this.lastB) {
                 this.lastRange.setB(range.getA().subtract(INTERVAL_GAP));
-            else // lastA >= lastB
+            }
+            else { // lastA >= lastB
                 this.lastRange.setA(range.getB().add(INTERVAL_GAP));
+            }
         }
 
-        for (int i = 0; i < values.length; ++i)
-            this.wst.getColumn(i).addColumnQRange(new ImportWstQRange(range, values[i]));
+        for (int i = 0; i < values.length; ++i) {
+            final ImportWstColumn column = this.wst.getColumn(i);
+            final ImportWstQRange wstQRange = new ImportWstQRange(range, values[i]);
+            column.addColumnQRange(wstQRange);
+        }
 
+        this.lastA = from.doubleValue();
+        this.lastB = to.doubleValue();
         this.lastRange = range;
     }
 


More information about the Dive4Elements-commits mailing list