package org.psjava.javautil;

import java.util.Iterator;

public class FilteredIterator {

	public static <T> Iterator<T> create(final Iterator<? extends T> a, final DataFilter<T> filter) {
		return new ReadOnlyIterator<T>() {
			T next = null;
			Iterator<? extends T> cursor = a;

			@Override
			public boolean hasNext() {
				tryToStepNext();
				return next != null;
			}

			@Override
			public T next() {
				tryToStepNext();
				T r = next;
				next = null;
				return r;
			}

			private void tryToStepNext() {
				if (next == null) {
					while (cursor.hasNext()) {
						T value = cursor.next();
						if (filter.isAccepted(value)) {
							next = value;
							break;
						}
					}
				}
			}

		};
	}

	private FilteredIterator() {
	}

}
@@ -543,18 +543,21 @@
  %7B%0D%0A%09%09%09%09
-if
+while
  (next =
@@ -566,25 +566,12 @@
 null
-) %7B%0D%0A%09%09%09%09%09while (
+ && 
 curs
@@ -583,25 +583,24 @@
 sNext()) %7B%0D%0A
-%09
 %09%09%09%09%09T value
@@ -623,17 +623,16 @@
 ;%0D%0A%09%09%09%09%09
-%09
 if (filt
@@ -652,21 +652,18 @@
 (value))
- %7B
 %0D%0A
-%09
 %09%09%09%09%09%09ne
@@ -679,40 +679,8 @@
 e;%0D%0A
-%09%09%09%09%09%09%09break;%0D%0A%09%09%09%09%09%09%7D%0D%0A%09%09%09%09%09%7D%0D%0A
 %09%09%09%09

make code simpler