Class UnmodifiableIterator<E,T extends Iterator<? extends E>>

java.lang.Object
org.apache.commons.collections4.iterators.UnmodifiableIterator<E,T>
Type Parameters:
E - The type of elements returned by this iterator.
T - The wrapped Iterator type.
All Implemented Interfaces:
Iterator<E>, Unmodifiable

public final class UnmodifiableIterator<E,T extends Iterator<? extends E>> extends Object implements Iterator<E>, Unmodifiable
Decorates an iterator such that it cannot be modified.

Calling remove() throws UnsupportedOperationException.

Since:
3.0
  • Field Details

    • iterator

      private final T extends Iterator<? extends E> iterator
      The decorated iterator.
  • Constructor Details

    • UnmodifiableIterator

      private UnmodifiableIterator(T iterator)
      Constructs a new instance.
      Parameters:
      iterator - The iterator to decorate.
  • Method Details

    • unmodifiableIterator

      public static <E> Iterator<E> unmodifiableIterator(Iterator<? extends E> iterator)
      Decorates the specified iterator such that it cannot be modified.

      If the iterator is already unmodifiable it is returned directly.

      Type Parameters:
      E - the element type
      Parameters:
      iterator - The iterator to decorate
      Returns:
      A new unmodifiable iterator
      Throws:
      NullPointerException - if the iterator is null
    • wrap

      static <E, T extends Iterator<? extends E>> UnmodifiableIterator<E,T> wrap(T iterator)
    • 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>
      Throws:
      UnsupportedOperationException - Always thrown.
    • unwrap

      T unwrap()