Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java @ 630:40d3039f85ac
ISSUE-40 (part I/II) Write values that the user had former selected / inserted into DESCRIBE document to preselect such data in the UI.
flys-artifacts/trunk@1995 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 24 May 2011 12:58:55 +0000 |
parents | c0c60a611fca |
children | 07640ab913fd |
rev | line source |
---|---|
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.Serializable; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.math.BigDecimal; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.List; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.flys.model.WstQRange; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.flys.model.Range; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 public class QRangeTree |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 implements Serializable |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public static class Node |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 implements Serializable |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 Node left; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 Node right; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 Node prev; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 Node next; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 double a; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 double b; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 double q; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 public Node() { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public Node(double a, double b, double q) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 this.a = a; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 this.b = b; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.q = q; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 protected final double interpolatePrev(double pos) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 /* |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 f(prev.b) = prev.q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 f(a) = q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 prev.q = m*prev.b + n |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 q = m*a + n <=> n = q - m*a |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 q - prev.q = m*(a - prev.b) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 m = (q - prev.q)/(a - prev.b) # a != prev.b |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 */ |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 if (a == prev.b) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 return 0.5*(q + prev.q); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 double m = (q - prev.q)/(a - prev.b); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 double n = q - m*a; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 return m*pos + n; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 protected final double interpolateNext(double pos) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 /* |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 f(next.a) = next.q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 f(b) = q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 next.q = m*next.a + n |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 q = m*b + n <=> n = q - m*b |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 q - next.q = m*(b - next.a) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 m = (q - next.q)/(b - next.a) # b != next.a |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 */ |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 if (b == next.a) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return 0.5*(q + next.q); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 double m = (q - next.q)/(b - next.a); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 double n = q - m*b; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 return m*pos + n; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 public double findQ(double pos) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 Node current = this; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 for (;;) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 if (pos < current.a) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 if (current.left != null) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 current = current.left; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 continue; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 return current.left != null |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 ? current.interpolatePrev(pos) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 : Double.NaN; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 if (pos > current.b) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 if (current.right != null) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 current = current.right; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 continue; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 return current.right != null |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 ? current.interpolateNext(pos) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 : Double.NaN; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 return current.q; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 } // class Node |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 protected Node root; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 public QRangeTree() { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 /** wstQRanges need to sorted by range.a */ |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 public QRangeTree(List<WstQRange> wstQRanges) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 if (wstQRanges.isEmpty()) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 return; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 Node [] nodes = new Node[wstQRanges.size()]; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 for (int i = 0; i < nodes.length; ++i) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 WstQRange wstQRange = wstQRanges.get(i); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 Range range = wstQRange.getRange(); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 BigDecimal a = range.getA(); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 BigDecimal b = range.getB(); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 nodes[i] = new Node( |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 a != null ? a.doubleValue() : -Double.MAX_VALUE, |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 b != null ? b.doubleValue() : Double.MAX_VALUE, |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 wstQRange.getQ().doubleValue()); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 for (int i = 0; i < nodes.length; ++i) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 Node node = nodes[i]; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 if (i > 0 ) node.prev = nodes[i-1]; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 if (i < nodes.length-1) node.next = nodes[i+1]; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 root = buildTree(nodes, 0, nodes.length-1); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 protected static Node buildTree(Node [] nodes, int lo, int hi) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 int mid = (lo + hi) >> 1; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 Node parent = nodes[mid]; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 if (hi > lo) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 parent.left = buildTree(nodes, lo, mid-1); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 parent.right = buildTree(nodes, mid+1, hi); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 return parent; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 public double findQ(double pos) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 return root != null ? root.findQ(pos) : Double.NaN; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |