Class IndexedPeekIterator<E>
- java.lang.Object
-
- com.github.wnameless.json.flattener.IndexedPeekIterator<E>
-
- Type Parameters:
E- the type of elements
- All Implemented Interfaces:
Iterator<E>
public final class IndexedPeekIterator<E> extends Object implements Iterator<E>
IndexedPeekIteratoris an Iterator which provides user apeek()method to peek an element advanced, agetIndex()method to get the index of last returned element and agetCurrent()method to get the last returned element itself.- Author:
- Wei-Ming Wu
-
-
Constructor Summary
Constructors Constructor Description IndexedPeekIterator(Iterator<? extends E> iterator)Creates anIndexedPeekIterator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EgetCurrent()Returns the last returned element.intgetIndex()Returns the index of last returned element.booleanhasNext()static <T> IndexedPeekIterator<T>newIndexedPeekIterator(Iterable<T> iter)Creates anIndexedPeekIteratorby given Iterable.Enext()Epeek()Peeks an element advanced.voidremove()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
IndexedPeekIterator
public IndexedPeekIterator(Iterator<? extends E> iterator)
Creates anIndexedPeekIterator.- Parameters:
iterator- an Iterator
-
-
Method Detail
-
newIndexedPeekIterator
public static <T> IndexedPeekIterator<T> newIndexedPeekIterator(Iterable<T> iter)
Creates anIndexedPeekIteratorby given Iterable.- Type Parameters:
T- the type of elements- Parameters:
iter- any Iterable- Returns:
- an
IndexedPeekIterator
-
getIndex
public int getIndex()
Returns the index of last returned element. If there is no element has been returned, it returns -1.- Returns:
- the index of last returned element
-
getCurrent
public E getCurrent()
Returns the last returned element. Ifnext()has never been called, it returns null.- Returns:
- the last returned element
-
peek
public E peek()
Peeks an element advanced. Warning: remove() is temporarily out of function after a peek() until a next() is called.- Returns:
- element
-
-