Class ReadOnlyIterator

  • All Implemented Interfaces:
    java.util.Iterator

    public class ReadOnlyIterator
    extends java.lang.Object
    implements java.util.Iterator
    Protects an given iterator by preventing calls to remove().
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Iterator base
      The base iterator which we protect.
    • Constructor Summary

      Constructors 
      Constructor Description
      ReadOnlyIterator​(java.util.Iterator it)
      Creates a new read-only iterator for the given iterator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()
      Returns true if the iteration has more elements.
      java.lang.Object next()
      Returns the next element in the iteration.
      void remove()
      Throws UnsupportedOperationException.
      • 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
    • Field Detail

      • base

        private java.util.Iterator base
        The base iterator which we protect.
    • Constructor Detail

      • ReadOnlyIterator

        public ReadOnlyIterator​(java.util.Iterator it)
        Creates a new read-only iterator for the given iterator.
        Parameters:
        it - the iterator.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
        Specified by:
        hasNext in interface java.util.Iterator
        Returns:
        true if the iterator has more elements.
      • next

        public java.lang.Object next()
        Returns the next element in the iteration. Throws NoSuchElementException when iteration has no more elements.
        Specified by:
        next in interface java.util.Iterator
        Returns:
        the next element in the iteration.
      • remove

        public void remove()
        Throws UnsupportedOperationException.
        Specified by:
        remove in interface java.util.Iterator