changeset 488:b316d2106598

River got a new method that returns all gauges intersected by a given start and end point. flys-backend/trunk@1829 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 05 May 2011 06:04:57 +0000
parents cf513cbe88c3
children e960098b1398
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/River.java
diffstat 2 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Tue May 03 17:40:02 2011 +0000
+++ b/flys-backend/ChangeLog	Thu May 05 06:04:57 2011 +0000
@@ -1,3 +1,9 @@
+2011-05-05  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/model/River.java: Added a method that
+	  returns all gauges of the river intersected by a given start and end
+	  point.
+
 2011-05-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/ImportTimeInterval.java:
--- a/flys-backend/src/main/java/de/intevation/flys/model/River.java	Tue May 03 17:40:02 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java	Thu May 05 06:04:57 2011 +0000
@@ -82,6 +82,29 @@
 
 
     /**
+     * This method returns the gauges that intersect with <i>a</i> and
+     * <i>b</i>,
+     *
+     * @param a A start point.
+     * @param b An end point.
+     *
+     * @return the intersecting gauges.
+     */
+    public List<Gauge> determineGauges(double a, double b) {
+        Session session = SessionHolder.HOLDER.get();
+
+        Query query = session.createQuery(
+            "from Gauge where river=:river " +
+            "and not (range.a > :b or range.b < :a) order by a");
+        query.setParameter("river", this);
+        query.setParameter("a", new BigDecimal(a));
+        query.setParameter("b", new BigDecimal(b));
+
+        return query.list();
+    }
+
+
+    /**
      * This method returns the first gauge that is intersected by <i>a</i> and
      * <i>b</i>,
      *
@@ -91,16 +114,7 @@
      * @return the first intersecting gauge.
      */
     public Gauge determineGauge(double a, double b) {
-        Session session = SessionHolder.HOLDER.get();
-
-        Query query = session.createQuery(
-            "from Gauge where river=:river " +
-            "and not (range.a > :b or range.b < :a) order by a");
-        query.setParameter("river", this);
-        query.setParameter("a", new BigDecimal(a));
-        query.setParameter("b", new BigDecimal(b));
-
-        List<Gauge> gauges = query.list();
+        List<Gauge> gauges = determineGauges(a, b);
 
         return gauges != null && gauges.size() > 0 ? gauges.get(0) : null;
     }

http://dive4elements.wald.intevation.org