1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package groovy.util.slurpersupport;
19
20 import java.util.Iterator;
21
22 /***
23 * @author John Wilson
24 *
25 */
26
27 public abstract class NodeIterator implements Iterator {
28 private final Iterator iter;
29 private Object nextNode;
30
31 public NodeIterator(final Iterator iter) {
32 this.iter = iter;
33 this.nextNode = getNextNode(iter);
34 }
35
36 public boolean hasNext() {
37 return this.nextNode != null;
38 }
39
40 public Object next() {
41 try {
42 return this.nextNode;
43 } finally {
44 this.nextNode = getNextNode(this.iter);
45 }
46 }
47
48 public void remove() {
49 throw new UnsupportedOperationException();
50 }
51
52 protected abstract Object getNextNode(final Iterator iter);
53 }