diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java @ 2609:ed550e325248

Little optimization when fetching q ranges for single columns of wsts. flys-artifacts/trunk@4191 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Apr 2012 14:41:31 +0000
parents 9144e5a5027b
children 62e5c6fd2a0c
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Tue Apr 03 13:46:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Tue Apr 03 14:41:31 2012 +0000
@@ -105,8 +105,40 @@
     public QRangeTree() {
     }
 
+    public static final class AccessQAB {
+        private int startIndex;
+
+        public AccessQAB(int startIndex) {
+            this.startIndex = startIndex;
+        }
+
+        public Double getQ(Object [] row) {
+            return (Double)row[startIndex];
+        }
+
+        public Double getA(Object [] row) {
+            return (Double)row[startIndex+1];
+        }
+
+        public Double getB(Object [] row) {
+            return (Double)row[startIndex+2];
+        }
+    }
+
+    public static final AccessQAB WITH_COLUMN    = new AccessQAB(1);
+    public static final AccessQAB WITHOUT_COLUMN = new AccessQAB(0);
+
     /** wstQRanges need to be sorted by range.a */
     public QRangeTree(List<Object []> qRanges, int start, int stop) {
+        this(qRanges, WITH_COLUMN, start, stop);
+    }
+
+    public QRangeTree(
+        List<Object []> qRanges,
+        AccessQAB       accessQAB, 
+        int             start,
+        int             stop
+    ) {
 
         if (stop <= start) {
             return;
@@ -115,9 +147,9 @@
         Node [] nodes = new Node[stop-start];
         for (int i = 0; i < nodes.length; ++i) {
             Object [] qRange = qRanges.get(start + i);
-            Double q = (Double)qRange[1];
-            Double a = (Double)qRange[2];
-            Double b = (Double)qRange[3];
+            Double q = accessQAB.getQ(qRange);
+            Double a = accessQAB.getA(qRange);
+            Double b = accessQAB.getB(qRange);
 
             nodes[i] = new Node(
                 a != null ? a.doubleValue() : -Double.MAX_VALUE,

http://dive4elements.wald.intevation.org