Mercurial Hosting > nabble
comparison src/nabble/model/FilteredNodeIterator.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 package nabble.model; | |
2 | |
3 import java.util.NoSuchElementException; | |
4 import fschmidt.util.java.Filter; | |
5 | |
6 | |
7 public final class FilteredNodeIterator extends NodeIterator<Node> { | |
8 private final NodeIterator<? extends Node> iter; | |
9 private final Filter<Node> filter; | |
10 private Node next = null; | |
11 | |
12 public FilteredNodeIterator(NodeIterator<? extends Node> iter,Filter<Node> filter) { | |
13 this.iter = iter; | |
14 this.filter = filter; | |
15 } | |
16 | |
17 public boolean hasNext() { | |
18 while( next == null && iter.hasNext() ) { | |
19 Node node = iter.next(); | |
20 if( filter.ok(node) ) | |
21 next = node; | |
22 } | |
23 return next != null; | |
24 } | |
25 | |
26 public Node next() throws NoSuchElementException { | |
27 if( !hasNext() ) | |
28 throw new NoSuchElementException(); | |
29 Node node = next; | |
30 next = null; | |
31 return node; | |
32 } | |
33 | |
34 public void close() { | |
35 iter.close(); | |
36 } | |
37 | |
38 } |