Class IntIterators.AbstractIndexBasedListIterator

java.lang.Object
All Implemented Interfaces:
BidirectionalIterator<java.lang.Integer>, IntBidirectionalIterator, IntIterator, IntListIterator, ObjectBidirectionalIterator<java.lang.Integer>, ObjectIterator<java.lang.Integer>, java.util.Iterator<java.lang.Integer>, java.util.ListIterator<java.lang.Integer>, java.util.PrimitiveIterator<java.lang.Integer,​java.util.function.IntConsumer>, java.util.PrimitiveIterator.OfInt
Enclosing class:
IntIterators

public abstract static class IntIterators.AbstractIndexBasedListIterator
extends IntIterators.AbstractIndexBasedIterator
implements IntListIterator
A skeletal implementation for a list-iterator backed by an index-based data store. High performance concrete implementations (like the main ListIterator of ArrayList) generally should avoid using this and just implement the interface directly, but should be decent for less performance critical implementations.

This class is only appropriate for sequences that are at most Integer.MAX_VALUE long. If your backing data store can be bigger then this, consider the equivalently named class in the type specific BigListSpliterators class.

As the abstract methods in this class are used in inner loops, it is generally a good idea to override the class as final as to encourage the JVM to inline them (or alternatively, override the abstract methods as final).

  • Method Details

    • hasPrevious

      public boolean hasPrevious()
      Description copied from interface: BidirectionalIterator
      Returns whether there is a previous element.
      Specified by:
      hasPrevious in interface BidirectionalIterator<java.lang.Integer>
      Specified by:
      hasPrevious in interface java.util.ListIterator<java.lang.Integer>
      Returns:
      whether there is a previous element.
      See Also:
      ListIterator.hasPrevious()
    • previousInt

      public int previousInt()
      Description copied from interface: IntBidirectionalIterator
      Returns the previous element as a primitive type.
      Specified by:
      previousInt in interface IntBidirectionalIterator
      Returns:
      the previous element in the iteration.
      See Also:
      ListIterator.previous()
    • nextIndex

      public int nextIndex()
      Specified by:
      nextIndex in interface java.util.ListIterator<java.lang.Integer>
    • previousIndex

      public int previousIndex()
      Specified by:
      previousIndex in interface java.util.ListIterator<java.lang.Integer>
    • add

      public void add​(int k)
      Description copied from interface: IntListIterator
      Inserts the specified element into the list (optional operation).

      This default implementation just throws an UnsupportedOperationException.

      Specified by:
      add in interface IntListIterator
      Parameters:
      k - the element to insert.
      See Also:
      ListIterator.add(Object)
    • set

      public void set​(int k)
      Description copied from interface: IntListIterator
      Replaces the last element returned by IntListIterator.next() or IntListIterator.previous() with the specified element (optional operation).
      Specified by:
      set in interface IntListIterator
      Parameters:
      k - the element used to replace the last element returned.

      This default implementation just throws an UnsupportedOperationException.

      See Also:
      ListIterator.set(Object)
    • back

      public int back​(int n)
      Description copied from interface: IntBidirectionalIterator
      Moves back for the given number of elements.

      The effect of this call is exactly the same as that of calling IntBidirectionalIterator.previous() for n times (possibly stopping if BidirectionalIterator.hasPrevious() becomes false).

      Specified by:
      back in interface IntBidirectionalIterator
      Specified by:
      back in interface ObjectBidirectionalIterator<java.lang.Integer>
      Parameters:
      n - the number of elements to skip back.
      Returns:
      the number of elements actually skipped.
      See Also:
      IntBidirectionalIterator.previous()