~ubuntu-branches/ubuntu/natty/jts/natty

« back to all changes in this revision

Viewing changes to src/com/vividsolutions/jts/geom/util/ShortCircuitedGeometryVisitor.java

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Baer
  • Date: 2005-08-07 14:12:35 UTC
  • Revision ID: james.westby@ubuntu.com-20050807141235-7hy3ll3xpq79djcb
Tags: upstream-1.6
ImportĀ upstreamĀ versionĀ 1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.vividsolutions.jts.geom.util;
 
2
 
 
3
import com.vividsolutions.jts.geom.*;
 
4
 
 
5
/**
 
6
 * A visitor to {@link Geometry} elements which can
 
7
 * be short-circuited by a given condition
 
8
 *
 
9
 * @version 1.6
 
10
 */
 
11
public abstract class ShortCircuitedGeometryVisitor
 
12
{
 
13
  private boolean isDone = false;
 
14
 
 
15
  public ShortCircuitedGeometryVisitor() {
 
16
  }
 
17
 
 
18
  public void applyTo(Geometry geom) {
 
19
    for (int i = 0; i < geom.getNumGeometries() && ! isDone; i++) {
 
20
      Geometry element = geom.getGeometryN(i);
 
21
      if (! (element instanceof GeometryCollection)) {
 
22
        visit(element);
 
23
        if (isDone()) {
 
24
          isDone = true;
 
25
          return;
 
26
        }
 
27
      }
 
28
      else
 
29
        applyTo(element);
 
30
    }
 
31
  }
 
32
 
 
33
  protected abstract void visit(Geometry element);
 
34
 
 
35
  protected abstract boolean isDone();
 
36
}