Class ImmutableIterator<T>

  • Type Parameters:
    T - The type of elements we are iterating over.
    All Implemented Interfaces:
    java.util.Iterator<T>

    public final class ImmutableIterator<T>
    extends java.lang.Object
    implements java.util.Iterator<T>
    Immutable implementation of the Iterator interface.

    The only methods that have actual implementations (that just defer to the underlying Iterator) are: hasNext() and next().

    Note: the remove() method implementation here has been taken out because there is now a default implementation in the Iterator interface itself in Java 8.

    • Constructor Summary

      Constructors 
      Constructor Description
      ImmutableIterator​(java.util.Iterator<T> iter)
      Construct an immutable iterator over the base iterator given here.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()  
      T next()  
      • 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, remove
    • Constructor Detail

      • ImmutableIterator

        public ImmutableIterator​(java.util.Iterator<T> iter)
        Construct an immutable iterator over the base iterator given here.
        Parameters:
        iter - The base iterator we want to protect from change.
        Throws:
        java.lang.IllegalArgumentException - if the iterator is null.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T>
      • next

        public T next()
        Specified by:
        next in interface java.util.Iterator<T>