Last active
August 29, 2015 14:03
-
-
Save jandk/a207b2f82d6c7986c054 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class IteratorWithCurrent<E> implements Iterator<E> | |
{ | |
private final Iterator<E> it; | |
private E current; | |
public IteratorWithCurrent(Iterable<E> iterable) { | |
it = iterable.iterator(); | |
} | |
public E current() { | |
if (current == null) { | |
throw new NoSuchElementException(); | |
} | |
return current; | |
} | |
@Override | |
public boolean hasNext() { | |
return it.hasNext(); | |
} | |
@Override | |
public E next() { | |
current = it.next(); | |
return current; | |
} | |
@Override | |
public void remove() { | |
it.remove(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment