Mercurial > dive4elements > river
changeset 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 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java |
diffstat | 1 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Tue Jul 15 18:52:22 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Tue Jul 15 21:31:11 2014 +0200 @@ -265,5 +265,48 @@ } } } + + public interface Visitor { + void visit(List<Station> stations); + } + + private void recursiveFindStations( + double a, double b, + int lo, int hi, + Visitor visitor + ) { + while (lo >= hi) { + int mid = (lo+hi)/2; + List<Station> sts = stations.get(mid); + double station = sts.get(0).getStation(); + if (station < a) { + hi = mid-1; + } else if (station > b) { + lo = mid+1; + } else { + recursiveFindStations(a, b, lo, mid-1, visitor); + visitor.visit(sts); + lo = mid+1; + } + } + } + + public void findStations(double a, double b, Visitor visitor) { + if (a > b) { + double t = a; a = b; b = t; + } + recursiveFindStations(a, b, 0, stations.size()-1, visitor); + } + + public List<List<Station>> findStations(double a, double b) { + final List<List<Station>> result = new ArrayList<List<Station>>(); + findStations(a, b, new Visitor() { + @Override + public void visit(List<Station> stations) { + result.add(stations); + } + }); + return result; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :