--- /dev/null
+package de.j32.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+public class FilteredIterator<E> implements Iterator<E>
+{
+ Iterator<E> base_;
+ Filter<E> filter_;
+ E next_;
+ boolean hasNext_ = true;
+
+ public FilteredIterator(Iterator<E> base, Filter<E> filter)
+ {
+ base_ = base;
+ filter_ = filter;
+ advance();
+ }
+
+ public E next()
+ {
+ if (hasNext_) {
+ E rv = next_;
+ advance();
+ return rv;
+ }
+ else throw new NoSuchElementException();
+ }
+
+ public boolean hasNext()
+ {
+ return hasNext_;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ void advance()
+ {
+ while (base_.hasNext()) {
+ next_ = base_.next();
+ if (filter_.match(next_)) return;
+ }
+ hasNext_ = false;
+ next_ = null;
+ }
+
+}