Class IndexedPeekIterator<E>

  • Type Parameters:
    E - the type of elements
    All Implemented Interfaces:
    Iterator<E>

    public final class IndexedPeekIterator<E>
    extends Object
    implements 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 Detail

      • IndexedPeekIterator

        public IndexedPeekIterator​(Iterator<? extends E> iterator)
        Parameters:
        iterator - an Iterator
    • Method Detail

      • 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. If next() has never been called, it returns null.
        Returns:
        the last returned element
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Iterator<E>
      • next

        public E next()
        Specified by:
        next in interface Iterator<E>
      • remove

        public void remove()
        Specified by:
        remove in interface Iterator<E>
      • 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