Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java @ 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 | 786bb4f87e8d |
children | 8c5eb9edc3f3 |
comparison
equal
deleted
inserted
replaced
8122:aca5d1c87755 | 8123:4a2ef6895557 |
---|---|
13 import java.util.Collections; | 13 import java.util.Collections; |
14 import java.util.Comparator; | 14 import java.util.Comparator; |
15 import java.util.Date; | 15 import java.util.Date; |
16 import java.util.List; | 16 import java.util.List; |
17 import java.util.TreeMap; | 17 import java.util.TreeMap; |
18 import java.util.TreeSet; | |
18 | 19 |
19 import org.dive4elements.river.utils.EpsilonComparator; | 20 import org.dive4elements.river.utils.EpsilonComparator; |
20 | 21 |
21 public class SedimentLoadData implements Serializable | 22 public class SedimentLoadData implements Serializable |
22 { | 23 { |
177 } | 178 } |
178 this.type = type; | 179 this.type = type; |
179 this.station = station; | 180 this.station = station; |
180 } | 181 } |
181 | 182 |
183 public void allLoads(Collection<Load> loads) { | |
184 for (List<Value> values: grainFractions) { | |
185 if (values != null) { | |
186 for (Value value: values) { | |
187 loads.add(value.getLoad()); | |
188 } | |
189 } | |
190 } | |
191 } | |
192 | |
182 public double getStation() { | 193 public double getStation() { |
183 return station; | 194 return station; |
184 } | 195 } |
185 | 196 |
186 public int getType() { | 197 public int getType() { |
378 private void recursiveFindStations( | 389 private void recursiveFindStations( |
379 double a, double b, | 390 double a, double b, |
380 int lo, int hi, | 391 int lo, int hi, |
381 Visitor visitor | 392 Visitor visitor |
382 ) { | 393 ) { |
383 while (lo >= hi) { | 394 while (lo <= hi) { |
384 int mid = (lo+hi)/2; | 395 int mid = (lo+hi)/2; |
385 Station st = stations[mid]; | 396 Station st = stations[mid]; |
386 double station = st.getStation(); | 397 double station = st.getStation(); |
387 if (station < a) { | 398 if (station < a) { |
388 hi = mid-1; | 399 hi = mid-1; |
394 lo = mid+1; | 405 lo = mid+1; |
395 } | 406 } |
396 } | 407 } |
397 } | 408 } |
398 | 409 |
410 public static final Comparator<Load> LOAD_ID_CMP = new Comparator<Load>() { | |
411 @Override | |
412 public int compare(Load a, Load b) { | |
413 return a.getId() - b.getId(); | |
414 } | |
415 }; | |
416 | |
417 public Collection<Load> findLoads(double a, double b) { | |
418 final TreeSet loads = new TreeSet<Load>(LOAD_ID_CMP); | |
419 | |
420 findStations(a, b, new Visitor() { | |
421 @Override | |
422 public void visit(Station station) { | |
423 station.allLoads(loads); | |
424 } | |
425 }); | |
426 | |
427 return loads; | |
428 } | |
429 | |
399 public void findStations(double a, double b, Visitor visitor) { | 430 public void findStations(double a, double b, Visitor visitor) { |
400 if (a > b) { | 431 if (a > b) { |
401 double t = a; a = b; b = t; | 432 double t = a; a = b; b = t; |
402 } | 433 } |
403 recursiveFindStations(a, b, 0, stations.length-1, visitor); | 434 recursiveFindStations(a, b, 0, stations.length-1, visitor); |