# HG changeset patch # User Sascha L. Teichmann # 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 loads) { + for (List 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_ID_CMP = new Comparator() { + @Override + public int compare(Load a, Load b) { + return a.getId() - b.getId(); + } + }; + + public Collection findLoads(double a, double b) { + final TreeSet loads = new TreeSet(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;