/*
 * Copyright (c) Andrey Kuznetsov. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  o Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 *  o Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 *  o Neither the name of imagero Andrey Kuznetsov nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.smartg.java.util;

import java.util.Enumeration;
import java.util.Iterator;

/**
 * Allows to filter values of Iterator.
 *
 * @param <E>
 */
public abstract class FilteredIterator<E> implements Enumeration<E>, Iterator<E>, IFilter<E> {

	private final Iterator<E> e;

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

	@Override
	public E next() {
		E nxt = next;
		next = getNext(e);
		return nxt;
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();
	}

	private E next;

	public FilteredIterator(Iterator<E> e) {
		this.e = e;
		next = getNext(e);
	}

	private E getNext(Iterator<E> e) {
		while (e.hasNext()) {
			E obj = e.next();
			if (obj != null && accept(obj)) {
				return obj;
			}
		}
		return null;
	}

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

	@Override
	public E nextElement() {
		E nxt = next;
		next = getNext(e);
		return nxt;
	}

	@Override
	public abstract boolean accept(E obj);
}

@@ -1664,16 +1664,79 @@
 terator;
+%0Aimport java.util.Objects;%0Aimport java.util.function.Predicate;
 %0A%0A/**%0A *
@@ -1801,25 +1801,16 @@
 %0Apublic 
-abstract 
 class Fi
@@ -1869,52 +1869,104 @@
 r%3CE%3E
-, IFilter%3CE%3E %7B%0A%0A%09private final Iterator%3CE%3E e
+ %7B%0A%0A%09private final Iterator%3CE%3E iterator;%0A%09private final Predicate%3CE%3E predicate;%0A%0A%09private E next
 ;%0A%0A%09
@@ -2085,33 +2085,40 @@
 %09next = getNext(
-e
+iterator
 );%0A%09%09return nxt;
@@ -2206,34 +2206,16 @@
 ();%0A%09%7D%0A%0A
-%09private E next;%0A%0A
 %09public 
@@ -2248,28 +2248,126 @@
 E%3E e
-) %7B%0A%09%09this.e = e;%0A%09%09
+, Predicate%3CE%3E p) %7B%0A%09%09this.iterator = Objects.requireNonNull(e);%0A%09%09this.predicate = Objects.requireNonNull(p);%0A%09%09this.
 next
@@ -2488,21 +2488,29 @@
 null && 
-accep
+predicate.tes
 t(obj)) 
@@ -2695,25 +2695,32 @@
 t = getNext(
-e
+iterator
 );%0A%09%09return 
@@ -2730,59 +2730,7 @@
 ;%0A%09%7D
-%0A%0A%09@Override%0A%09public abstract boolean accept(E obj);
 %0A%7D%0A

Update FilteredIterator.java