[PATCH] Sediment load: Fixed findStations() and add findLoads()

Wald Commits scm-commit at wald.intevation.org
Mon Aug 25 12:05:41 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1408961137 -7200
# Node ID 4a2ef6895557ec0eaf52c112cc574afc6c8fdbe8
# Parent  aca5d1c87755994f70bc04fb5ca37a1d4c8bafd9
Sediment load: Fixed findStations() and  add findLoads().

diff -r aca5d1c87755 -r 4a2ef6895557 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Fri Aug 22 18:00:35 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Mon Aug 25 12:05:37 2014 +0200
@@ -15,6 +15,7 @@
 import java.util.Date;
 import java.util.List;
 import java.util.TreeMap;
+import java.util.TreeSet;
 
 import org.dive4elements.river.utils.EpsilonComparator;
 
@@ -179,6 +180,16 @@
             this.station = station;
         }
 
+        public void allLoads(Collection<Load> loads) {
+            for (List<Value> values: grainFractions) {
+                if (values != null) {
+                    for (Value value: values) {
+                        loads.add(value.getLoad());
+                    }
+                }
+            }
+        }
+
         public double getStation() {
             return station;
         }
@@ -380,7 +391,7 @@
         int lo, int hi,
         Visitor visitor
     ) {
-        while (lo >= hi) {
+        while (lo <= hi) {
             int mid = (lo+hi)/2;
             Station st = stations[mid];
             double station = st.getStation();
@@ -396,6 +407,26 @@
         }
     }
 
+    public static final Comparator<Load> LOAD_ID_CMP = new Comparator<Load>() {
+        @Override
+        public int compare(Load a, Load b) {
+            return a.getId() - b.getId();
+        }
+    };
+
+    public Collection<Load> findLoads(double a, double b) {
+        final TreeSet loads = new TreeSet<Load>(LOAD_ID_CMP);
+
+        findStations(a, b, new Visitor() {
+            @Override
+            public void visit(Station station) {
+                station.allLoads(loads);
+            }
+        });
+
+        return loads;
+    }
+
     public void findStations(double a, double b, Visitor visitor) {
         if (a > b) {
             double t = a; a = b; b = t;


More information about the Dive4Elements-commits mailing list