01: package org.geotools.caching.quatree;
02:
03: import org.geotools.caching.spatialindex.spatialindex.IData;
04: import org.geotools.caching.spatialindex.spatialindex.INode;
05: import org.geotools.caching.spatialindex.spatialindex.IVisitor;
06:
07: public class InvalidatingVisitor implements IVisitor {
08: protected Node lastNode = null;
09:
10: public void visitData(IData d) {
11: // do nothing
12: }
13:
14: public void visitNode(INode n) {
15: if (n instanceof Node) {
16: Node node = (Node) n;
17: node.entry.invalidate();
18: lastNode = node;
19: }
20: }
21:
22: public void updateTree() {
23: lastNode.subNodes.clear();
24:
25: Node parent = lastNode.parent;
26:
27: while (parent != null) {
28: if (isInvalid(parent)) {
29: parent.entry.invalidate();
30: parent.subNodes.clear();
31: parent = parent.parent;
32: } else {
33: // we don't have to climb the tree any more
34: break;
35: }
36: }
37: }
38:
39: protected boolean isInvalid(Node n) {
40: boolean ret = true;
41:
42: for (int i = 0; i < n.getChildrenCount(); i++) {
43: Node child = n.getSubNode(i);
44:
45: if ((!child.isLeaf()) || child.isValid()) {
46: ret = false;
47:
48: break;
49: }
50: }
51:
52: return ret;
53: }
54: }
|