Class NonNullSingletonIterator<T>

  • All Implemented Interfaces:
    java.util.Iterator<T>

    public class NonNullSingletonIterator<T>
    extends java.lang.Object
    implements java.util.Iterator<T>
    A singleton iterator for an object which is guaranteed to be not-null. Exploiting this invariant allows this class to be slightly more efficient than Collections.iterator()
    • Constructor Detail

      • NonNullSingletonIterator

        public NonNullSingletonIterator​(T o)
        Parameters:
        o - the single object in this collection, must be non-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>
      • remove

        public void remove()
                    throws java.lang.UnsupportedOperationException
        Specified by:
        remove in interface java.util.Iterator<T>
        Throws:
        java.lang.UnsupportedOperationException