changeset 2610:3c907758f0ab

Added cacheable model for fixing column. flys-artifacts/trunk@4192 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Apr 2012 16:51:03 +0000 (2012-04-03)
parents ed550e325248
children 62e5c6fd2a0c
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java
diffstat 2 files changed, 61 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java	Tue Apr 03 16:51:03 2012 +0000
@@ -0,0 +1,55 @@
+package de.intevation.flys.artifacts.model;
+
+import de.intevation.flys.artifacts.math.Linear;
+
+import java.util.Arrays;
+
+import java.io.Serializable;
+
+public class FixingsColumn
+implements   Serializable
+{
+    protected int columnId;
+
+    protected double [] kms;
+    protected double [] ws;
+
+    protected QRangeTree qs;
+
+    public FixingsColumn() {
+    }
+
+    public FixingsColumn(
+        int       columnId, 
+        double [] kms,
+        double [] ws
+    ) {
+        this.columnId = columnId;
+        this.kms      = kms;
+        this.ws       = ws;
+    }
+
+    public int getColumnId() {
+        return columnId;
+    }
+
+    public double getW(double km) {
+
+        if (km < kms[0] || km > kms[kms.length-1]) {
+            return Double.NaN;
+        }
+
+        int idx = Arrays.binarySearch(kms, km);
+
+        if (idx >= 0) return ws[idx];
+
+        idx = -idx - 1;
+
+        return Linear.linear(km, kms[idx], kms[idx+1], ws[idx], ws[idx+1]);
+    }
+
+    public double getQ(double km) {
+        return qs.findQ(km);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Tue Apr 03 14:41:31 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Tue Apr 03 16:51:03 2012 +0000
@@ -236,21 +236,22 @@
      */
     protected static List<WstValueTable.Row> loadRowsOneColumn(
         Session session,
-        int     wst_id,
+        int     wstId,
         int     column_pos
     ) {
         SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS_AT_COL)
-            .addScalar("km",         StandardBasicTypes.DOUBLE)
-            .addScalar("w",          StandardBasicTypes.DOUBLE);
+            .addScalar("km", StandardBasicTypes.DOUBLE)
+            .addScalar("w",  StandardBasicTypes.DOUBLE);
 
-        sqlQuery.setInteger("wst_id", wst_id);
+        sqlQuery.setInteger("wst_id", wstId);
         sqlQuery.setInteger("column_pos", column_pos);
 
         List<Object []> results = sqlQuery.list();
 
         double [] ws = null;
 
-        ArrayList<WstValueTable.Row> rows = new ArrayList<WstValueTable.Row>();
+        List<WstValueTable.Row> rows =
+            new ArrayList<WstValueTable.Row>(results.size());
 
         // Walk over rows.
         for (Object [] result: results) {
@@ -263,7 +264,6 @@
             ws[0] = w != null ? w : Double.NaN;
         }
 
-        rows.trimToSize();
         return rows;
     }
 

http://dive4elements.wald.intevation.org