changeset 328:07e642030172

Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge. flys-artifacts/trunk@1726 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Apr 2011 10:32:31 +0000
parents e09634fbf6bc
children 0b2358bc716d
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java
diffstat 2 files changed, 50 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Apr 18 16:01:23 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Apr 19 10:32:31 2011 +0000
@@ -1,3 +1,9 @@
+2011-04-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
+	  Added convenience constructors/methods to ease the access to the master
+	  discharge table of a gauge.
+
 2011-04-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Mon Apr 18 16:01:23 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Tue Apr 19 10:32:31 2011 +0000
@@ -20,6 +20,10 @@
 public class DischargeTables
 implements   Serializable
 {
+    public static final double DEFAULT_SCALE = 100.0;
+
+    public static final int MASTER = 0;
+
     private static Logger log = Logger.getLogger(DischargeTables.class);
 
     protected List<String> gaugeNames;
@@ -28,21 +32,56 @@
 
     protected double scale;
 
+    protected int    kind;
+
     protected Map<String, double [][]> values;
 
     public DischargeTables() {
     }
 
-    public DischargeTables(String riverName, String [] gaugeNames) {
-        this(riverName, Arrays.asList(gaugeNames));
+    public DischargeTables(String riverName, String gaugeName) {
+        this(riverName, gaugeName, MASTER);
     }
 
-    public DischargeTables(String riverName, List<String> gaugeNames) {
+    public DischargeTables(String riverName, String gaugeName, int kind) {
+        this(riverName, new String [] { gaugeName }, kind);
+    }
+
+    public DischargeTables(String riverName, String [] gaugeNames) {
+        this(riverName, gaugeNames, MASTER);
+    }
+
+    public DischargeTables(String riverName, String [] gaugeNames, int kind) {
+        this(riverName, Arrays.asList(gaugeNames), kind);
+    }
+
+    public DischargeTables(
+        String       riverName,
+        List<String> gaugeNames,
+        int          kind
+    ) {
         scale           = Double.NaN;
+        this.kind       = kind;
         this.riverName  = riverName;
         this.gaugeNames = gaugeNames;
     }
 
+    public double [][] getFirstTable() {
+        return getFirstTable(DEFAULT_SCALE);
+    }
+
+    public double [][] getFirstTable(double scale) {
+        Map<String, double [][]> values = getValues(scale);
+        for (double [][] table: values.values()) {
+            return table;
+        }
+        return null;
+    }
+
+    public Map<String, double [][]> getValues() {
+        return getValues(DEFAULT_SCALE);
+    }
+
     public Map<String, double [][]> getValues(double scale) {
         if (values == null || scale != this.scale) {
             values = loadValues(scale);
@@ -57,8 +96,9 @@
         Session session = SessionHolder.HOLDER.get();
 
         Query gaugeQuery = session.createQuery(
-            "from Gauge where name=:gauge and river.name=:river");
+            "from Gauge where name=:gauge and river.name=:river and kind=:kind");
         gaugeQuery.setParameter("river", riverName);
+        gaugeQuery.setInteger("kind", kind);
 
         for (String gaugeName: gaugeNames) {
             gaugeQuery.setParameter("gauge", gaugeName);

http://dive4elements.wald.intevation.org