1 9 10 package org.ozoneDB.xml.dom4j.o3impl; 11 12 import java.util.Iterator ; 13 import java.util.NoSuchElementException ; 14 15 21 public abstract class FilterIterator implements Iterator { 22 23 protected Iterator proxy; 24 private Object next; 25 private boolean first = true; 26 27 public FilterIterator(Iterator proxy) { 28 this.proxy = proxy; 29 } 30 31 32 public boolean hasNext() { 33 if (first) { 34 next = findNext(); 35 first = false; 36 } 37 return next != null; 38 } 39 40 public Object next() throws NoSuchElementException { 41 if (!hasNext()) { 42 throw new NoSuchElementException (); 43 } 44 Object answer = this.next; 45 this.next = findNext(); 46 return answer; 47 } 48 49 55 public void remove() { 56 throw new UnsupportedOperationException (); 57 } 58 59 64 protected abstract boolean matches(Object element); 65 66 67 protected Object findNext() { 68 if (proxy != null) { 69 while (proxy.hasNext()) { 70 Object next = proxy.next(); 71 if (next != null && matches(next)) { 72 return next; 73 } 74 } 75 proxy = null; 76 } 77 return null; 78 } 79 } 80 81 82 126 | Popular Tags |