comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java @ 8035:f2dc7992b8a3

Sediment loads from cache are sorted in station order so range filters are pretty easy to implement.
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 15 Jul 2014 21:31:11 +0200
parents b6e7cfcabf2c
children 17542d100e75
comparison
equal deleted inserted replaced
8034:b6e7cfcabf2c 8035:f2dc7992b8a3
263 } 263 }
264 } 264 }
265 } 265 }
266 } 266 }
267 } 267 }
268
269 public interface Visitor {
270 void visit(List<Station> stations);
271 }
272
273 private void recursiveFindStations(
274 double a, double b,
275 int lo, int hi,
276 Visitor visitor
277 ) {
278 while (lo >= hi) {
279 int mid = (lo+hi)/2;
280 List<Station> sts = stations.get(mid);
281 double station = sts.get(0).getStation();
282 if (station < a) {
283 hi = mid-1;
284 } else if (station > b) {
285 lo = mid+1;
286 } else {
287 recursiveFindStations(a, b, lo, mid-1, visitor);
288 visitor.visit(sts);
289 lo = mid+1;
290 }
291 }
292 }
293
294 public void findStations(double a, double b, Visitor visitor) {
295 if (a > b) {
296 double t = a; a = b; b = t;
297 }
298 recursiveFindStations(a, b, 0, stations.size()-1, visitor);
299 }
300
301 public List<List<Station>> findStations(double a, double b) {
302 final List<List<Station>> result = new ArrayList<List<Station>>();
303 findStations(a, b, new Visitor() {
304 @Override
305 public void visit(List<Station> stations) {
306 result.add(stations);
307 }
308 });
309 return result;
310 }
268 } 311 }
269 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 312 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org