01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.support;
16:
17: import java.util.Collection;
18: import java.util.Collections;
19: import java.util.Iterator;
20:
21: /**
22: * Iterates through all the points in an {@link EditGeom} starting with the shell
23: * and then doing the holes in order
24: *
25: * @author Jesse
26: * @since 1.1.0
27: */
28: public class EditGeomPointIterator implements Iterator<Point> {
29: private final Iterator<PrimitiveShape> currentShape;
30: private Iterator<Point> current;
31: private Point next;
32: private final Collection<Point> selectedPoints;
33:
34: /**
35: * New instance
36: *
37: * @param geom Geometry to draw
38: * @param selectedPoints points <em>NOT</em> to draw.
39: */
40: public EditGeomPointIterator(EditGeom geom,
41: Collection<Point> selectedPoints) {
42: currentShape = geom.iterator();
43: current = currentShape.next().iterator();
44: this .selectedPoints = selectedPoints;
45: }
46:
47: public EditGeomPointIterator(EditGeom geom) {
48: this (geom, Collections.<Point> emptySet());
49: }
50:
51: public boolean hasNext() {
52: if (next != null)
53: return true;
54: do {
55: next = getNext();
56: } while (next != null && selectedPoints.contains(next));
57:
58: return next != null;
59: }
60:
61: private Point getNext() {
62: if (current.hasNext()) {
63: return current.next();
64: }
65:
66: if (currentShape.hasNext()) {
67: current = currentShape.next().iterator();
68: return getNext();
69: }
70:
71: return null;
72: }
73:
74: public Point next() {
75: Point result = next;
76: next = null;
77: return result;
78: }
79:
80: public void remove() {
81: throw new UnsupportedOperationException();
82: }
83:
84: }
|