comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java @ 6984:77f48c104d23

Backed out changeset 6b9402377d07
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 11 Sep 2013 09:46:11 +0200
parents 7be97faf5848
children d12363a7d84a
comparison
equal deleted inserted replaced
6983:93e7f947f6fa 6984:77f48c104d23
11 import gnu.trove.TDoubleArrayList; 11 import gnu.trove.TDoubleArrayList;
12 12
13 import java.util.Calendar; 13 import java.util.Calendar;
14 import java.util.Date; 14 import java.util.Date;
15 import java.util.List; 15 import java.util.List;
16 import java.util.Map;
17 import java.util.TreeMap; 16 import java.util.TreeMap;
18 17
19 import net.sf.ehcache.Cache; 18 import net.sf.ehcache.Cache;
20 import net.sf.ehcache.Element; 19 import net.sf.ehcache.Element;
21 20
485 return load; 484 return load;
486 } 485 }
487 return new SedimentLoad(); 486 return new SedimentLoad();
488 } 487 }
489 488
490
491 /**
492 * Returns range of matching measurementstation.
493 * If no direct match is found, the measurement-station with
494 * the next lower station is taken - but only if km is still in
495 * its range.
496 *
497 * The end of the range is the beginning of the next range (next as in
498 * next greater station), or if it is the last, by its own ranges end.
499 *
500 * @param stations Map of station to measurementstation (attention:
501 * the range of a m.station does not necessarily
502 * begin at the registered station).
503 * @param km The station for which to find a measurementstation.
504 *
505 * @return The validity range of a station (interereted as described above
506 * for given km or null if none found.
507 */
508 protected static Range findMeasurementStationRange( 489 protected static Range findMeasurementStationRange(
509 TreeMap<Double, MeasurementStation> stations, 490 TreeMap<Double, MeasurementStation> stations,
510 double km 491 double km
511 ) { 492 ) {
512 Map.Entry<Double, MeasurementStation> entry = stations.floorEntry(km); 493 MeasurementStation station = stations.get(km);
513 if (entry == null) { 494 if (station == null) {
514 return null; 495 return null;
515 } 496 }
516 MeasurementStation station = entry.getValue();
517 if (station == null
518 || station.getRange() == null
519 || !station.getRange().contains(km)) {
520 return null;
521 }
522 497
523 double endKm; 498 double endKm;
524 499
525 Map.Entry<Double, MeasurementStation> ceilingEntry = 500 if (stations.ceilingEntry(km + 0.1d) != null) {
526 stations.ceilingEntry(km + 0.1d); 501 MeasurementStation nextStation = stations.ceilingEntry(km + 0.1d).getValue();
527
528 if (ceilingEntry != null) {
529 MeasurementStation nextStation = ceilingEntry.getValue();
530 endKm = nextStation.getRange().getA().doubleValue(); 502 endKm = nextStation.getRange().getA().doubleValue();
531 } 503 }
532 else { 504 else {
533 // TODO end-of-river instead of B. 505 // TODO end-of-river instead of B.
534 endKm = station.getRange().getB().doubleValue(); 506 endKm = station.getRange().getB().doubleValue();
536 508
537 return new Range( 509 return new Range(
538 station.getRange().getA().doubleValue(), 510 station.getRange().getA().doubleValue(),
539 endKm); 511 endKm);
540 } 512 }
541
542 513
543 /** 514 /**
544 * Run query with grain parameter set to fraction, feed result into 515 * Run query with grain parameter set to fraction, feed result into
545 * load. Create load if null. 516 * load. Create load if null.
546 * 517 *

http://dive4elements.wald.intevation.org