changeset 465:c2c3ad4fda58

Added a method to River that returns the min and max distance of the river. flys-backend/trunk@1698 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 14 Apr 2011 13:43:53 +0000
parents d37ccb04ab5d
children 8bd50b41dea6
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/River.java
diffstat 2 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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	<sascha.teichmann@intevation.de>
 
 	* src/**/*.java: Removed trailing whitespace.
--- 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 :

http://dive4elements.wald.intevation.org