Class EmptyIterator

  • All Implemented Interfaces:
    Iterator, Iterator

    public class EmptyIterator
    extends Object
    implements Iterator
    Singleton Iterator for an empty collection. The usage of the singleton-pattern for this simple object allows just to save some memory.
    Version:
    $Date$ $Revision$
    Author:
    Fabio Bellifemine, TILAB
    • Method Detail

      • getInstance

        public static Iterator getInstance()
        Returns the singleton EmptyIterator object. Most of the methods of this class are instance methods and must be invoked with respect to the singleton object.
      • hasNext

        public boolean hasNext()
        Checks whether the iterator can scan further.
        Specified by:
        hasNext in interface Iterator
        Returns:
        This method always returns false.
      • next

        public Object next()
        Retrieves the next element in the collection scanned by this iterator.
        Specified by:
        next in interface Iterator
        Returns:
        This method always throws an exception.
        Throws:
        NoSuchElementException - Always, because the underlying collection is always empty.
      • remove

        public void remove()
        Remove the element pointed to by this iterator from the collection.
        Specified by:
        remove in interface Iterator
        Throws:
        RuntimeException - Always, because the underlying collection is always empty.