[PATCH 2 of 7] SedimentLoadFactory: Extracted method to find range of matching

Wald Commits scm-commit at wald.intevation.org
Thu Sep 5 15:37:47 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1378387434 -7200
# Node ID 5a348e3df0f8147803d1ee815f0a76c6d0e1017f
# Parent  aa1d681ee6eb4c75bbc09b5f322769cef57a9f03
SedimentLoadFactory: Extracted method to find range of matching
measurement station.

diff -r aa1d681ee6eb -r 5a348e3df0f8 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Thu Sep 05 11:48:38 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Thu Sep 05 15:23:54 2013 +0200
@@ -486,6 +486,31 @@
         return new SedimentLoad();
     }
 
+    protected static Range findMeasurementStationRange(
+        TreeMap<Double, MeasurementStation> stations,
+        double km
+    ) {
+        MeasurementStation station = stations.get(km);
+        MeasurementStation nextStation = null;
+        if (stations.ceilingEntry(km + 0.1d) != null) {
+            nextStation = stations.ceilingEntry(km + 0.1d).getValue();
+        }
+        Range range = null;
+        if (station == null) {
+            return null;
+        }
+        else {
+            if (nextStation != null)
+                range = new Range(station.getRange().getA().doubleValue(),
+                    nextStation.getRange().getA().doubleValue());
+            else {
+                // TODO end-of-river instead of B.
+                range = new Range(station.getRange().getA().doubleValue(),
+                    station.getRange().getB().doubleValue());
+            }
+        }
+        return range;
+    }
 
     /**
      * Run query with grain parameter set to fraction, feed result into
@@ -520,26 +545,11 @@
         for (int i = 0; i < results.size(); i++) {
             Object[] row = results.get(i);
             double km = (Double)row[3];
-            MeasurementStation station = stations.get(km);
-            MeasurementStation nextStation = null;
-            if (stations.ceilingEntry(km + 0.1d) != null) {
-                nextStation = stations.ceilingEntry(km + 0.1d).getValue();
-            }
-            Range range = null;
-            if (station == null) {
+            Range range = findMeasurementStationRange(stations, km);
+            if (range == null) {
                 log.warn("No measurement station for " + fraction + " km " + km);
                 continue;
             }
-            else {
-                if (nextStation != null)
-                    range = new Range(station.getRange().getA().doubleValue(),
-                        nextStation.getRange().getA().doubleValue());
-                else {
-                    // TODO end-of-river instead of B.
-                    range = new Range(station.getRange().getA().doubleValue(),
-                        station.getRange().getB().doubleValue());
-                }
-            }
             double v = -1;
             if (row[2] != null) {
                 v = ((Double)row[2]).doubleValue();


More information about the Dive4elements-commits mailing list