changeset 2383:6605dcd6745f

Added a method to build a map from gauge stations to the datums of the gauges. flys-backend/trunk@3907 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 03 Feb 2012 15:25:18 +0000
parents c5791de0c495
children 385170ff7b34
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	Thu Jan 19 13:36:06 2012 +0000
+++ b/flys-backend/ChangeLog	Fri Feb 03 15:25:18 2012 +0000
@@ -1,3 +1,10 @@
+2012-01-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/model/River.java(getGaugeDatumsKMs):
+	  New method to build a map of gauge stattion km to 
+	  the datums (PNP) of the gauge.  Useful look if a km 
+	  is a gauge station.
+
 2012-01-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/FastAnnotations.java:
--- a/flys-backend/src/main/java/de/intevation/flys/model/River.java	Thu Jan 19 13:36:06 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java	Fri Feb 03 15:25:18 2012 +0000
@@ -17,6 +17,9 @@
 import javax.persistence.GenerationType;
 
 import java.util.List;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.TreeMap;
 
 import org.hibernate.Session;
 import org.hibernate.Query;
@@ -31,6 +34,18 @@
 {
     public static final MathContext PRECISION = new MathContext(6);
 
+    public static final double EPSILON = 1e-5;
+
+    public static final Comparator KM_CMP = new Comparator<Double>() {
+        @Override
+        public int compare(Double a, Double b) {
+            double diff = a - b;
+            if (diff < -EPSILON) return -1;
+            if (diff >  EPSILON) return +1;
+            return 0;
+        }
+    };
+
     private Integer id;
 
     private String  name;
@@ -258,5 +273,20 @@
 
         return minmax;
     }
+
+    public Map<Double, Double> getGaugeDatumsKMs() {
+        List<Gauge> gauges = getGauges();
+        Map result = new TreeMap<Double, Double>(KM_CMP);
+
+        for (Gauge gauge: gauges) {
+            BigDecimal km    = gauge.getStation();
+            BigDecimal datum = gauge.getDatum();
+            if (km != null && datum != null) {
+                result.put(km.doubleValue(), datum.doubleValue());
+            }
+        }
+
+        return result;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org