Class EmptyIterator

java.lang.Object
io.github.jmcleodfoss.pst.EmptyIterator
All Implemented Interfaces:
Iterator<Object>

public class EmptyIterator
extends Object
implements Iterator<Object>
The EmptyIterator class is an iterator for empty lists. It is useful in some circumstances when one wishes to avoid checking for null in client code.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static EmptyIterator iterator
    A generic EmptyIterator object which may be used by anyone, and has no state, so it can be shared.
  • Constructor Summary

    Constructors 
    Constructor Description
    EmptyIterator()  
  • Method Summary

    Modifier and Type Method Description
    boolean hasNext()
    Are there any more elements to return? Note that there are never any more elements in an EmptyIterator.
    Object next()
    Get the next element.
    void remove()
    The remove function is not supported by the EmptyIterator iterator.

    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 Details

    • iterator

      public static final EmptyIterator iterator
      A generic EmptyIterator object which may be used by anyone, and has no state, so it can be shared.
  • Constructor Details

  • Method Details

    • hasNext

      public boolean hasNext()
      Are there any more elements to return? Note that there are never any more elements in an EmptyIterator. return false, always (the EmptyIterator never contains any elements, by definition.
      Specified by:
      hasNext in interface Iterator<Object>
    • next

      public Object next()
      Get the next element. This function should never be called (since hasNext always returns true). In fact, calling this function is a programming error, and the UnsupportedOperationExcpetion will be thrown. returns Nothing - calling this function results in an exception being thrown.
      Specified by:
      next in interface Iterator<Object>
    • remove

      public void remove()
      The remove function is not supported by the EmptyIterator iterator.
      Specified by:
      remove in interface Iterator<Object>