changeset 8123:4a2ef6895557

Sediment load: Fixed findStations() and add findLoads().
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 25 Aug 2014 12:05:37 +0200
parents aca5d1c87755
children 2c21fd1ade39
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
diffstat 1 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;

http://dive4elements.wald.intevation.org