Class CursorableLinkedList.Cursor<E>

  • All Implemented Interfaces:
    java.util.Iterator<E>, java.util.ListIterator<E>, OrderedIterator<E>
    Enclosing class:
    CursorableLinkedList<E>

    public static class CursorableLinkedList.Cursor<E>
    extends java.lang.Object
    An extended ListIterator that allows concurrent changes to the underlying list.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(E obj)
      Adds an object to the list.
      void close()
      Mark this cursor as no longer being needed.
      int nextIndex()
      Gets the index of the next element to be returned.
      void remove()
      Removes the item last returned by this iterator.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Method Detail

      • remove

        public void remove()
        Removes the item last returned by this iterator.

        There may have been subsequent alterations to the list since you obtained this item, however you can still remove it. You can even remove it if the item is no longer in the main list. However, you can't call this method on the same iterator more than once without calling next() or previous().

        Specified by:
        remove in interface java.util.Iterator<E>
        Specified by:
        remove in interface java.util.ListIterator<E>
        Throws:
        java.lang.IllegalStateException - if there is no item to remove
      • add

        public void add​(E obj)
        Adds an object to the list. The object added here will be the new 'previous' in the iterator.
        Specified by:
        add in interface java.util.ListIterator<E>
        Parameters:
        obj - the object to add
      • nextIndex

        public int nextIndex()
        Gets the index of the next element to be returned.
        Specified by:
        nextIndex in interface java.util.ListIterator<E>
        Returns:
        the next index
      • close

        public void close()
        Mark this cursor as no longer being needed. Any resources associated with this cursor are immediately released. In previous versions of this class, it was mandatory to close all cursor objects to avoid memory leaks. It is no longer necessary to call this close method; an instance of this class can now be treated exactly like a normal iterator.