changeset 3142:9aed2e4de3ca

FixA: Moved GaugeFinder into top level class. flys-artifacts/trunk@4750 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 21 Jun 2012 15:50:58 +0000
parents 3582e87e9171
children 29022c93027d
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeFinder.java
diffstat 3 files changed, 132 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Jun 21 15:39:34 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Jun 21 15:50:58 2012 +0000
@@ -1,3 +1,11 @@
+2012-06-21	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/GaugeFinder.java:
+	  New. Moved out of FixingsOverview.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java:
+	  Moved GaugeFinder into top level class.
+	  
 2012-06-21	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/GaugeRange.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java	Thu Jun 21 15:39:34 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java	Thu Jun 21 15:50:58 2012 +0000
@@ -48,29 +48,6 @@
         "    g.river_id = :river_id " +
         "ORDER BY r.a";
 
-    public static final String SQL_DISCHARGE_SECTORS =
-        "SELECT" +
-        "    g.id                            AS gauge_id," +
-        "    nmv.name                        AS name," +
-        "    CAST(mv.value AS NUMERIC(38,2)) AS value " +
-        "FROM gauges g" +
-        "    JOIN main_values       mv  ON g.id = mv.gauge_id" +
-        "    JOIN named_main_values nmv ON nmv.id = mv.named_value_id" +
-        "    JOIN main_value_types  mvt ON nmv.type_id = mvt.id " +
-        "WHERE" +
-        "    mvt.name = 'Q' AND (" +
-        "        nmv.name = 'MNQ'      OR" +
-        "        nmv.name LIKE 'MNQ(%' OR" +
-        "        nmv.name = 'MQ'       OR" +
-        "        nmv.name LIKE 'MQ(%'  OR" +
-        "        nmv.name = 'MHQ'      OR" +
-        "        nmv.name LIKE 'MHQ(%' OR" +
-        "        nmv.name = 'HQ5'      OR" +
-        "        nmv.name LIKE 'HQ5(%') AND" +
-        "    g.river_id = :river_id " +
-        "ORDER BY" +
-        "    g.id";
-
     public static final String SQL_FIXINGS =
         "SELECT" +
         "    id AS wst_id," +
@@ -112,90 +89,6 @@
         "    wst_column_id = :column_id";
 
 
-    public static class GaugeFinder {
-
-        protected List<GaugeRange> gauges;
-        protected boolean          isKmUp;
-
-        public GaugeFinder(List<GaugeRange> gauges) {
-            this(gauges, true);
-        }
-
-        public GaugeFinder(
-            List<GaugeRange> gauges,
-            boolean          isKmUp
-        ) {
-            this.gauges = gauges;
-            this.isKmUp = isKmUp;
-        }
-
-        public boolean getIsKmUp() {
-            return isKmUp;
-        }
-
-        public void setIsKmUp(boolean isKmUp) {
-            this.isKmUp = isKmUp;
-        }
-
-        public GaugeRange find(Range range) {
-            double km = isKmUp ? range.start : range.end;
-            for (GaugeRange gauge: gauges) {
-                if (gauge.inside(km)) {
-                    return gauge;
-                }
-            }
-            return null;
-        }
-
-        public GaugeRange find(int gaugeId) {
-            for (GaugeRange gauge: gauges) {
-                if (gauge.gaugeId == gaugeId) {
-                    return gauge;
-                }
-            }
-            return null;
-        }
-
-        public boolean loadDischargeSectors(Session session, int riverId) {
-
-            SQLQuery query = session.createSQLQuery(SQL_DISCHARGE_SECTORS)
-                .addScalar("gauge_id", StandardBasicTypes.INTEGER)
-                .addScalar("name",     StandardBasicTypes.STRING)
-                .addScalar("value",    StandardBasicTypes.DOUBLE);
-
-            query.setInteger("river_id", riverId);
-
-            List<Object []> list = query.list();
-
-            if (list.isEmpty()) {
-                log.warn("River " + riverId + " has no discharge sectors.");
-                return false;
-            }
-
-            GaugeRange gauge = null;
-
-            for (Object [] row: list) {
-                int    gaugeId = (Integer)row[0];
-                String label   = (String) row[1];
-                Double value   = (Double) row[2];
-
-                if (gauge == null || gauge.gaugeId != gaugeId) {
-                    if ((gauge = find(gaugeId)) == null) {
-                        log.warn("Cannot find gauge for id " + gaugeId + ".");
-                        continue;
-                    }
-                }
-
-                gauge.addMainValue(label, value);
-            }
-
-            for (GaugeRange g: gauges) {
-                g.buildClasses();
-            }
-
-            return true;
-        }
-    } // class GaugeFinder
 
     public static class QRange extends Range {
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeFinder.java	Thu Jun 21 15:50:58 2012 +0000
@@ -0,0 +1,124 @@
+package de.intevation.flys.artifacts.model;
+
+import java.io.Serializable;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+
+import org.hibernate.type.StandardBasicTypes;
+
+public class GaugeFinder
+implements   Serializable
+{
+    private static Logger log = Logger.getLogger(GaugeFinder.class);
+
+    public static final String SQL_DISCHARGE_SECTORS =
+        "SELECT" +
+        "    g.id                            AS gauge_id," +
+        "    nmv.name                        AS name," +
+        "    CAST(mv.value AS NUMERIC(38,2)) AS value " +
+        "FROM gauges g" +
+        "    JOIN main_values       mv  ON g.id = mv.gauge_id" +
+        "    JOIN named_main_values nmv ON nmv.id = mv.named_value_id" +
+        "    JOIN main_value_types  mvt ON nmv.type_id = mvt.id " +
+        "WHERE" +
+        "    mvt.name = 'Q' AND (" +
+        "        nmv.name = 'MNQ'      OR" +
+        "        nmv.name LIKE 'MNQ(%' OR" +
+        "        nmv.name = 'MQ'       OR" +
+        "        nmv.name LIKE 'MQ(%'  OR" +
+        "        nmv.name = 'MHQ'      OR" +
+        "        nmv.name LIKE 'MHQ(%' OR" +
+        "        nmv.name = 'HQ5'      OR" +
+        "        nmv.name LIKE 'HQ5(%') AND" +
+        "    g.river_id = :river_id " +
+        "ORDER BY" +
+        "    g.id";
+
+    protected List<GaugeRange> gauges;
+    protected boolean          isKmUp;
+
+    public GaugeFinder(List<GaugeRange> gauges) {
+        this(gauges, true);
+    }
+
+    public GaugeFinder(
+        List<GaugeRange> gauges,
+        boolean          isKmUp
+    ) {
+        this.gauges = gauges;
+        this.isKmUp = isKmUp;
+    }
+
+    public boolean getIsKmUp() {
+        return isKmUp;
+    }
+
+    public void setIsKmUp(boolean isKmUp) {
+        this.isKmUp = isKmUp;
+    }
+
+    public GaugeRange find(Range range) {
+        double km = isKmUp ? range.start : range.end;
+        for (GaugeRange gauge: gauges) {
+            if (gauge.inside(km)) {
+                return gauge;
+            }
+        }
+        return null;
+    }
+
+    public GaugeRange find(int gaugeId) {
+        for (GaugeRange gauge: gauges) {
+            if (gauge.gaugeId == gaugeId) {
+                return gauge;
+            }
+        }
+        return null;
+    }
+
+    public boolean loadDischargeSectors(Session session, int riverId) {
+
+        SQLQuery query = session.createSQLQuery(SQL_DISCHARGE_SECTORS)
+            .addScalar("gauge_id", StandardBasicTypes.INTEGER)
+            .addScalar("name",     StandardBasicTypes.STRING)
+            .addScalar("value",    StandardBasicTypes.DOUBLE);
+
+        query.setInteger("river_id", riverId);
+
+        List<Object []> list = query.list();
+
+        if (list.isEmpty()) {
+            log.warn("River " + riverId + " has no discharge sectors.");
+            return false;
+        }
+
+        GaugeRange gauge = null;
+
+        for (Object [] row: list) {
+            int    gaugeId = (Integer)row[0];
+            String label   = (String) row[1];
+            Double value   = (Double) row[2];
+
+            if (gauge == null || gauge.gaugeId != gaugeId) {
+                if ((gauge = find(gaugeId)) == null) {
+                    log.warn("Cannot find gauge for id " + gaugeId + ".");
+                    continue;
+                }
+            }
+
+            gauge.addMainValue(label, value);
+        }
+
+        for (GaugeRange g: gauges) {
+            g.buildClasses();
+        }
+
+        return true;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org