Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
2608:938e2f6c0c9a | 2609:ed550e325248 |
---|---|
103 protected Node root; | 103 protected Node root; |
104 | 104 |
105 public QRangeTree() { | 105 public QRangeTree() { |
106 } | 106 } |
107 | 107 |
108 public static final class AccessQAB { | |
109 private int startIndex; | |
110 | |
111 public AccessQAB(int startIndex) { | |
112 this.startIndex = startIndex; | |
113 } | |
114 | |
115 public Double getQ(Object [] row) { | |
116 return (Double)row[startIndex]; | |
117 } | |
118 | |
119 public Double getA(Object [] row) { | |
120 return (Double)row[startIndex+1]; | |
121 } | |
122 | |
123 public Double getB(Object [] row) { | |
124 return (Double)row[startIndex+2]; | |
125 } | |
126 } | |
127 | |
128 public static final AccessQAB WITH_COLUMN = new AccessQAB(1); | |
129 public static final AccessQAB WITHOUT_COLUMN = new AccessQAB(0); | |
130 | |
108 /** wstQRanges need to be sorted by range.a */ | 131 /** wstQRanges need to be sorted by range.a */ |
109 public QRangeTree(List<Object []> qRanges, int start, int stop) { | 132 public QRangeTree(List<Object []> qRanges, int start, int stop) { |
133 this(qRanges, WITH_COLUMN, start, stop); | |
134 } | |
135 | |
136 public QRangeTree( | |
137 List<Object []> qRanges, | |
138 AccessQAB accessQAB, | |
139 int start, | |
140 int stop | |
141 ) { | |
110 | 142 |
111 if (stop <= start) { | 143 if (stop <= start) { |
112 return; | 144 return; |
113 } | 145 } |
114 | 146 |
115 Node [] nodes = new Node[stop-start]; | 147 Node [] nodes = new Node[stop-start]; |
116 for (int i = 0; i < nodes.length; ++i) { | 148 for (int i = 0; i < nodes.length; ++i) { |
117 Object [] qRange = qRanges.get(start + i); | 149 Object [] qRange = qRanges.get(start + i); |
118 Double q = (Double)qRange[1]; | 150 Double q = accessQAB.getQ(qRange); |
119 Double a = (Double)qRange[2]; | 151 Double a = accessQAB.getA(qRange); |
120 Double b = (Double)qRange[3]; | 152 Double b = accessQAB.getB(qRange); |
121 | 153 |
122 nodes[i] = new Node( | 154 nodes[i] = new Node( |
123 a != null ? a.doubleValue() : -Double.MAX_VALUE, | 155 a != null ? a.doubleValue() : -Double.MAX_VALUE, |
124 b != null ? b.doubleValue() : Double.MAX_VALUE, | 156 b != null ? b.doubleValue() : Double.MAX_VALUE, |
125 q.doubleValue()); | 157 q.doubleValue()); |