changeset 6964:5a348e3df0f8

SedimentLoadFactory: Extracted method to find range of matching measurement station.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 05 Sep 2013 15:23:54 +0200
parents aa1d681ee6eb
children 69bf96202df4
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
diffstat 1 files changed, 27 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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();

http://dive4elements.wald.intevation.org