comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java @ 8040:f1500a524b76

Replace station list with a plain array.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 16 Jul 2014 16:03:50 +0200
parents 3a769d5fb733
children 01ad09af0975
comparison
equal deleted inserted replaced
8039:3a769d5fb733 8040:f1500a524b76
252 return null; 252 return null;
253 } 253 }
254 } // class Station 254 } // class Station
255 255
256 256
257 private List<Station> stations; 257 private Station [] stations;
258 258
259 public SedimentLoadData() { 259 public SedimentLoadData() {
260 } 260 }
261 261
262 public SedimentLoadData(Collection<Station> stations) { 262 public SedimentLoadData(Collection<Station> stations) {
274 same.put(key, station); 274 same.put(key, station);
275 } else { 275 } else {
276 st.append(station); 276 st.append(station);
277 } 277 }
278 } 278 }
279 this.stations = new ArrayList<Station>(same.values()); 279 this.stations = new Station[same.size()];
280 int i = 0;
281 for (Station station: same.values()) {
282 this.stations[i++] = station;
283 }
280 wireNeighbors(); 284 wireNeighbors();
281 } 285 }
282 286
283 private void wireNeighbors() { 287 private void wireNeighbors() {
284 for (int i = 0, N = stations.size(); i < N-1; ++i) { 288 for (int i = 0, N = stations.length; i < N-1; ++i) {
285 for (Station curr = stations.get(i); curr != null; curr = curr.nextChain()) { 289 for (Station curr = stations[i]; curr != null; curr = curr.nextChain()) {
286 int type = curr.getType(); 290 int type = curr.getType();
287 NEXT: for (int j = i+1; j < N; ++j) { 291 NEXT: for (int j = i+1; j < N; ++j) {
288 Station next = stations.get(j).firstOfType(type); 292 Station next = stations[j].firstOfType(type);
289 if (next != null) { 293 if (next != null) {
290 curr.setNext(next); 294 curr.setNext(next);
291 next.setPrev(curr); 295 next.setPrev(curr);
292 break NEXT; 296 break NEXT;
293 } 297 }
301 int lo, int hi, 305 int lo, int hi,
302 Visitor visitor 306 Visitor visitor
303 ) { 307 ) {
304 while (lo >= hi) { 308 while (lo >= hi) {
305 int mid = (lo+hi)/2; 309 int mid = (lo+hi)/2;
306 Station st = stations.get(mid); 310 Station st = stations[mid];
307 double station = st.getStation(); 311 double station = st.getStation();
308 if (station < a) { 312 if (station < a) {
309 hi = mid-1; 313 hi = mid-1;
310 } else if (station > b) { 314 } else if (station > b) {
311 lo = mid+1; 315 lo = mid+1;
319 323
320 public void findStations(double a, double b, Visitor visitor) { 324 public void findStations(double a, double b, Visitor visitor) {
321 if (a > b) { 325 if (a > b) {
322 double t = a; a = b; b = t; 326 double t = a; a = b; b = t;
323 } 327 }
324 recursiveFindStations(a, b, 0, stations.size()-1, visitor); 328 recursiveFindStations(a, b, 0, stations.length-1, visitor);
325 } 329 }
326 330
327 public List<Station> findStations(double a, double b) { 331 public List<Station> findStations(double a, double b) {
328 final List<Station> result = new ArrayList<Station>(); 332 final List<Station> result = new ArrayList<Station>();
329 findStations(a, b, new Visitor() { 333 findStations(a, b, new Visitor() {

http://dive4elements.wald.intevation.org