01: package com.vividsolutions.jts.geom.util;
02:
03: import com.vividsolutions.jts.geom.*;
04:
05: /**
06: * A visitor to {@link Geometry} elements which can
07: * be short-circuited by a given condition
08: *
09: * @version 1.7
10: */
11: public abstract class ShortCircuitedGeometryVisitor {
12: private boolean isDone = false;
13:
14: public ShortCircuitedGeometryVisitor() {
15: }
16:
17: public void applyTo(Geometry geom) {
18: for (int i = 0; i < geom.getNumGeometries() && !isDone; i++) {
19: Geometry element = geom.getGeometryN(i);
20: if (!(element instanceof GeometryCollection)) {
21: visit(element);
22: if (isDone()) {
23: isDone = true;
24: return;
25: }
26: } else
27: applyTo(element);
28: }
29: }
30:
31: protected abstract void visit(Geometry element);
32:
33: protected abstract boolean isDone();
34: }
|