# HG changeset patch # User Ingo Weinzierl # Date 1302788633 0 # Node ID c2c3ad4fda58e4669e6ad85a129cfe91f15ce252 # Parent d37ccb04ab5d3c224e510b9a4eefc6f7287aa231 Added a method to River that returns the min and max distance of the river. flys-backend/trunk@1698 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r d37ccb04ab5d -r c2c3ad4fda58 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Sun Apr 03 10:41:27 2011 +0000 +++ b/flys-backend/ChangeLog Thu Apr 14 13:43:53 2011 +0000 @@ -1,3 +1,8 @@ +2011-04-14 Ingo Weinzierl + + * src/main/java/de/intevation/flys/model/River.java: Added a method that + returns the min and max distance of a river. + 2011-04-03 Sascha L. Teichmann * src/**/*.java: Removed trailing whitespace. diff -r d37ccb04ab5d -r c2c3ad4fda58 flys-backend/src/main/java/de/intevation/flys/model/River.java --- a/flys-backend/src/main/java/de/intevation/flys/model/River.java Sun Apr 03 10:41:27 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java Thu Apr 14 13:43:53 2011 +0000 @@ -2,6 +2,8 @@ import java.io.Serializable; +import java.math.BigDecimal; + import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @@ -71,5 +73,35 @@ public String toString() { return name != null ? name : ""; } + + /** + * Returns the min and max distance of this river. The first position in the + * resulting array contains the min distance, the second position the max + * distance. + * + * @return the min and max distance of this river. + */ + public double[] determineMinMaxDistance() { + if (gauges == null) { + return null; + } + + double minmax[] = new double[] { Double.MAX_VALUE, Double.MIN_VALUE }; + + for (Gauge g: gauges) { + Range r = g.getRange(); + + double a = r.getA().doubleValue(); + minmax[0] = minmax[0] < a ? minmax[0] : a; + + BigDecimal bigB = r.getB(); + if (bigB != null) { + double b = bigB.doubleValue(); + minmax[1] = minmax[1] > b ? minmax[1] : b; + } + } + + return minmax; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :