01: package org.geotools.caching.quatree;
02:
03: import org.geotools.caching.spatialindex.spatialindex.Region;
04:
05: import java.util.ArrayList;
06: import java.util.Iterator;
07: import java.util.Stack;
08:
09: public class MissingTileQueryStrategy implements QueryStrategy {
10: private final Region target;
11: private final Node startNode;
12: private boolean firstCall = true;
13: private Stack nodes = new Stack();
14: private ArrayList regions = new ArrayList();
15:
16: public MissingTileQueryStrategy(Region target, Node startNode) {
17: this .target = target;
18: this .startNode = startNode;
19: }
20:
21: public Node getNextNode(Node current, boolean[] hasNext) {
22: if (firstCall) {
23: firstCall = false;
24: hasNext[0] = true;
25:
26: return startNode;
27: }
28:
29: if (current.getShape().intersects(target)) {
30: if (current.isLeaf() && !current.isValid()) {
31: Region missing = (Region) current.getShape();
32:
33: for (Iterator it = regions.iterator(); it.hasNext();) {
34: Region r = (Region) it.next();
35:
36: if (missing.intersects(r)) {
37: missing = missing.combinedRegion(r);
38: it.remove();
39: }
40: }
41:
42: regions.add(missing);
43: } else {
44: for (int i = 0; i < current.getChildrenCount(); i++) {
45: nodes.push(current.getSubNode(i));
46: }
47: }
48: }
49:
50: if (!nodes.isEmpty()) {
51: hasNext[0] = true;
52:
53: return (Node) nodes.pop();
54: } else {
55: hasNext[0] = false;
56:
57: return null;
58: }
59: }
60: }
|