changeset 8987:5ff8ce9a2e06

Modification of the range adding fixed
author mschaefer
date Sun, 08 Apr 2018 18:08:35 +0200
parents 392bbcd8a88b
children ae76f618d990
files backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
diffstat 1 files changed, 23 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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
-        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));
+            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);
+
         // 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;
     }
 

http://dive4elements.wald.intevation.org