Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 53d954973610 |
children | bcf25d8c183e |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.artifacts.model; | |
2 | |
3 import de.intevation.flys.utils.DataUtil; | |
4 | |
5 import gnu.trove.TDoubleArrayList; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 public class W | |
10 extends NamedObjectImpl | |
11 { | |
12 private static Logger log = Logger.getLogger(W.class); | |
13 | |
14 protected TDoubleArrayList ws; | |
15 | |
16 public W() { | |
17 ws = new TDoubleArrayList(); | |
18 } | |
19 | |
20 public W(String name) { | |
21 super(name); | |
22 ws = new TDoubleArrayList(); | |
23 } | |
24 | |
25 public W(int capacity) { | |
26 this(capacity, ""); | |
27 } | |
28 | |
29 public W(int capacity, String name) { | |
30 super(name); | |
31 ws = new TDoubleArrayList(capacity); | |
32 } | |
33 | |
34 public void add(double value) { | |
35 ws.add(value); | |
36 } | |
37 | |
38 public int size() { | |
39 return ws.size(); | |
40 } | |
41 | |
42 public double getW(int idx) { | |
43 return ws.getQuick(idx); | |
44 } | |
45 | |
46 public double [] getWs() { | |
47 return ws.toNativeArray(); | |
48 } | |
49 | |
50 public double [] get(int idx) { | |
51 return get(idx, new double [1]); | |
52 } | |
53 | |
54 public double [] get(int idx, double [] dst) { | |
55 dst[0] = ws.getQuick(idx); | |
56 return dst; | |
57 } | |
58 | |
59 public double minWs() { | |
60 return ws.min(); | |
61 } | |
62 | |
63 public static void removeNaNs(TDoubleArrayList [] arrays) { | |
64 | |
65 int dest = 0; | |
66 | |
67 int A = arrays.length; | |
68 int N = arrays[0].size(); | |
69 | |
70 OUTER: for (int i = 0; i < N; ++i) { | |
71 for (int j = 0; j < A; ++j) { | |
72 TDoubleArrayList a = arrays[j]; | |
73 double v = a.getQuick(i); | |
74 if (Double.isNaN(v)) { | |
75 continue OUTER; | |
76 } | |
77 a.setQuick(dest, v); | |
78 } | |
79 ++dest; | |
80 } | |
81 | |
82 if (dest < N) { | |
83 for (int i = 0; i < A; ++i) { | |
84 arrays[i].remove(dest, N-dest); | |
85 } | |
86 } | |
87 } | |
88 | |
89 public void removeNaNs() { | |
90 removeNaNs(new TDoubleArrayList [] { ws }); | |
91 } | |
92 | |
93 public boolean guessWaterIncreasing() { | |
94 return guessWaterIncreasing(0.05f); | |
95 } | |
96 | |
97 public boolean guessWaterIncreasing(float factor) { | |
98 return DataUtil.guessWaterIncreasing(ws, factor); | |
99 } | |
100 | |
101 public int [] longestIncreasingWRangeIndices() { | |
102 return longestIncreasingWRangeIndices(new int[2]); | |
103 } | |
104 | |
105 public int [] longestIncreasingWRangeIndices(int [] bounds) { | |
106 | |
107 int N = size(); | |
108 int start = 0; | |
109 int stop = 0; | |
110 | |
111 double lastW = Double.MAX_VALUE; | |
112 | |
113 for (int i = 0; i < N; ++i) { | |
114 double v = ws.getQuick(i); | |
115 if (v <= lastW) { | |
116 if (stop-start > bounds[1]-bounds[0]) { | |
117 bounds[0] = start; | |
118 bounds[1] = stop; | |
119 if (log.isDebugEnabled()) { | |
120 log.debug("new range: " + | |
121 bounds[0] + " - " + bounds[1] + " (" + | |
122 ws.getQuick(bounds[0]) + ", " + | |
123 ws.getQuick(bounds[1]) + ")"); | |
124 | |
125 } | |
126 } | |
127 start = stop = i; | |
128 } | |
129 else { | |
130 stop = i; | |
131 } | |
132 lastW = v; | |
133 } | |
134 | |
135 if (stop-start > bounds[1]-bounds[0]) { | |
136 bounds[0] = start; | |
137 bounds[1] = stop; | |
138 if (log.isDebugEnabled()) { | |
139 log.debug("new range @end: " + | |
140 bounds[0] + " - " + bounds[1] + " (" + | |
141 ws.getQuick(bounds[0]) + ", " + | |
142 ws.getQuick(bounds[1]) + ")"); | |
143 } | |
144 } | |
145 | |
146 return bounds; | |
147 } | |
148 } | |
149 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |