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>
IndexedPeekIterator is an Iterator which provides user a peek() method to peek
an element advanced, a getIndex() method to get the index of last returned element and a
getCurrent() method to get the last returned element itself.- Author:
- Wei-Ming Wu
-
Constructor Summary
ConstructorsConstructorDescriptionIndexedPeekIterator(Iterator<? extends E> iterator) Creates anIndexedPeekIterator. -
Method Summary
Modifier and TypeMethodDescriptionReturns 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.next()peek()Peeks an element advanced.voidremove()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
IndexedPeekIterator
Creates anIndexedPeekIterator.- Parameters:
iterator- an Iterator
-
-
Method Details
-
newIndexedPeekIterator
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
Returns the last returned element. Ifnext()has never been called, it returns null.- Returns:
- the last returned element
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
peek
Peeks an element advanced. Warning: remove() is temporarily out of function after a peek() until a next() is called.- Returns:
- element
-