Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 8755:30b1ddadf275
(issue1801) Unify reference gauge finding code
The basic way as described in the method comment of the
determineRefGauge method is now used in the WINFOArtifact,
MainValuesService and RiverUtils.getGauge method.
RiverUtils.getGauge previously just returned the first
gauge found. While this is now a behavior change I believe
that it is always more correct then the undeterministic
behavior of the previous implmenentation.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 24 Jun 2015 14:07:26 +0200 |
parents | 1655588ed479 |
children | 26dedebbe39f |
comparison
equal
deleted
inserted
replaced
8754:574f8b80799f | 8755:30b1ddadf275 |
---|---|
432 } | 432 } |
433 | 433 |
434 /** | 434 /** |
435 * Return the (first) Gauge corresponding to the given location(s) of | 435 * Return the (first) Gauge corresponding to the given location(s) of |
436 * the artifact. | 436 * the artifact. |
437 * | |
438 * This method is left for compatibility. Use river.determineRefGauge() | |
439 * directly in new code. | |
440 * | |
437 * @param flys the artifact in question. | 441 * @param flys the artifact in question. |
438 * @return (First) gauge of locations of river of artifact. | 442 * @return Reference / first gauge of locations of river of artifact. |
439 */ | 443 */ |
440 public static Gauge getGauge(D4EArtifact flys) { | 444 public static Gauge getGauge(D4EArtifact flys) { |
441 River river = getRiver(flys); | 445 River river = getRiver(flys); |
442 | |
443 if (river == null) { | |
444 log.debug("no river found"); | |
445 return null; | |
446 } | |
447 | |
448 RangeAccess rangeAccess = new RangeAccess(flys); | 446 RangeAccess rangeAccess = new RangeAccess(flys); |
449 double[] dist = rangeAccess.getKmRange(); | 447 double[] dist = rangeAccess.getKmRange(); |
450 | 448 |
451 if (dist == null) { | 449 return river.determineRefGauge(dist, rangeAccess.isRange()); |
452 log.debug("no range found"); | |
453 return null; | |
454 } | |
455 | |
456 if (log.isDebugEnabled()) { | |
457 log.debug("Determine gauge for:"); | |
458 log.debug("... river: " + river.getName()); | |
459 log.debug("... distance: " + dist[0] + " - " + dist[1]); | |
460 } | |
461 | |
462 Gauge gauge = river.determineGauge(dist[0], dist[1]); | |
463 | |
464 String name = gauge != null ? gauge.getName() : "'n/a"; | |
465 log.debug("Found gauge: " + name); | |
466 | |
467 return gauge; | |
468 } | 450 } |
469 | 451 |
470 | 452 |
471 public static String getGaugename(D4EArtifact flys) { | 453 public static String getGaugename(D4EArtifact flys) { |
472 Gauge gauge = getGauge(flys); | 454 Gauge gauge = getGauge(flys); |