Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java @ 8242:f8ea1a7ecde6
(issue1448) Fix info service for epoch / periods and off epoch
This also includes a bit cleanup to move the sqRelationTimeInterval check
to the creation of the load list in SedimentLoadData allLoads.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 09 Sep 2014 11:13:37 +0200 |
parents | 61fd22f65bd4 |
children | 5ffbf97766f7 |
comparison
equal
deleted
inserted
replaced
8241:a65afd85d516 | 8242:f8ea1a7ecde6 |
---|---|
228 } | 228 } |
229 } | 229 } |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 public void allOfficialLoads(Collection<Load> loads) { | |
234 for (List<Value> values: grainFractions) { | |
235 if (values != null) { | |
236 for (Value value: values) { | |
237 Load load = value.getLoad(); | |
238 if (load.getKind() == 1) { | |
239 loads.add(value.getLoad()); | |
240 } | |
241 } | |
242 } | |
243 } | |
244 } | |
245 | |
246 public void allLoads(Collection<Load> loads, Integer sqRelationTimeInterval) { | |
247 | |
248 for (List<Value> values: grainFractions) { | |
249 if (values == null) { | |
250 continue; | |
251 } | |
252 for (Value value: values) { | |
253 Load load = value.getLoad(); | |
254 Integer sqId = load.getSQRelationTimeIntervalId(); | |
255 if ((sqRelationTimeInterval == null) | |
256 || sqId != null && sqId.equals(sqRelationTimeInterval)) { | |
257 loads.add(load); | |
258 } | |
259 } | |
260 } | |
261 } | |
262 | |
233 public double getStation() { | 263 public double getStation() { |
234 return station; | 264 return station; |
235 } | 265 } |
236 | 266 |
237 public int getType() { | 267 public int getType() { |
433 public int compare(Load a, Load b) { | 463 public int compare(Load a, Load b) { |
434 return a.getId() - b.getId(); | 464 return a.getId() - b.getId(); |
435 } | 465 } |
436 }; | 466 }; |
437 | 467 |
468 public static final Comparator<Load> LOAD_TI_CMP = new Comparator<Load>() { | |
469 @Override | |
470 public int compare(Load a, Load b) { | |
471 Date a_start = a.getStartTime(); | |
472 Date a_stop = a.getStopTime(); | |
473 Date b_start = b.getStartTime(); | |
474 Date b_stop = b.getStopTime(); | |
475 if (a_start == null && b_start == null) { | |
476 return 0; | |
477 } else if (a_start != null) { | |
478 return a_start.compareTo(b_start); | |
479 } else if (a_stop != null) { | |
480 return a_stop.compareTo(b_stop); | |
481 } else { | |
482 return 1; | |
483 } | |
484 } | |
485 }; | |
486 | |
438 public static final Comparator<Load> LOAD_SQ_TI_CMP = new Comparator<Load>() { | 487 public static final Comparator<Load> LOAD_SQ_TI_CMP = new Comparator<Load>() { |
439 @Override | 488 @Override |
440 public int compare(Load a, Load b) { | 489 public int compare(Load a, Load b) { |
441 Integer a_id = a.getSQRelationTimeIntervalId(); | 490 Integer a_id = a.getSQRelationTimeIntervalId(); |
442 Integer b_id = b.getSQRelationTimeIntervalId(); | 491 Integer b_id = b.getSQRelationTimeIntervalId(); |
452 return a_id - b_id; | 501 return a_id - b_id; |
453 } | 502 } |
454 }; | 503 }; |
455 | 504 |
456 /** Find all loads in the range a/b with the according sq_time_interval */ | 505 /** Find all loads in the range a/b with the according sq_time_interval */ |
457 public Collection<Load> findLoads(double a, double b, Integer sqRelationTimeInterval) { | 506 public Collection<Load> findLoads(double a, double b, final Integer sqRelationTimeInterval) { |
458 final TreeSet<Load> loads = new TreeSet<Load>(LOAD_ID_CMP); | 507 final TreeSet<Load> loads = new TreeSet<Load>(LOAD_ID_CMP); |
459 | 508 |
460 findStations(a, b, new Visitor() { | 509 findStations(a, b, new Visitor() { |
461 @Override | 510 @Override |
462 public void visit(Station station) { | 511 public void visit(Station station) { |
463 station.allLoads(loads); | 512 station.allLoads(loads, sqRelationTimeInterval); |
464 } | 513 } |
465 }); | 514 }); |
466 | 515 |
467 /* This may not be the most beautiful thing to do but well,.. */ | 516 return loads; |
468 for (Iterator<Load> it = loads.iterator(); it.hasNext();) { | 517 } |
469 Integer obj = it.next().getSQRelationTimeIntervalId(); | 518 |
470 if ((obj == null && sqRelationTimeInterval != null) || | 519 /** Find all official loads with a distinct time interval id */ |
471 (obj != null && !obj.equals(sqRelationTimeInterval))) { | 520 public Collection<Load> findUniqueTiOfficialLoads(double a, double b) { |
472 it.remove(); | 521 final TreeSet<Load> loads = new TreeSet<Load>(LOAD_TI_CMP); |
473 } | 522 |
474 } | 523 findStations(a, b, new Visitor() { |
524 @Override | |
525 public void visit(Station station) { | |
526 station.allOfficialLoads(loads); | |
527 } | |
528 }); | |
475 | 529 |
476 return loads; | 530 return loads; |
477 } | 531 } |
478 | 532 |
479 /** Get a list of loads with unique sq_time_intervals. | 533 /** Get a list of loads with unique sq_time_intervals. |