Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jmmo.iterator;
 
User: Tomas Date: 20.01.14 Time: 19:28
public abstract class FilteredIterator<E> implements Iterator<E> {
    private final Iterator<E> iterator;
    private Iterator<E> nextOption = Iterators.<E>empty().iterator();
    public FilteredIterator(Iterator<E> iterator) {
        this. = iterator;
    }
    @Override
    public boolean hasNext() {
        if (.hasNext()) {
            return true;
        }
        while (.hasNext()) {
            final E next = .next();
            if (test(next)) {
                 = Iterators.singleton(next).iterator();
                return true;
            }
        }
        return false;
    }
    @Override
    public E next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        return .next();
    }
    @Override
    public void remove() {
        .remove();
    }
    abstract public boolean test(E e);
New to GrepCode? Check out our FAQ X