Class DefaultListIterator<E>

java.lang.Object
com.globalmentor.collections.iterators.AbstractListIterator<E,E>
com.globalmentor.collections.iterators.DefaultListIterator<E>
Type Parameters:
E - The type of element contained in the list.
All Implemented Interfaces:
Iterator<E>, ListIterator<E>

public class DefaultListIterator<E> extends AbstractListIterator<E,E>
A default list iterator that can iterate over a given list.
Author:
Garret Wilson
  • Constructor Details

    • DefaultListIterator

      public DefaultListIterator(List<E> list)
      List constructor starting at the first index.
      Parameters:
      list - The list over which to iterate.
      Throws:
      NullPointerException - if the given list is null.
    • DefaultListIterator

      public DefaultListIterator(List<E> list, int index)
      List and index constructor.
      Parameters:
      list - The list over which to iterate.
      index - The index of first value to be returned from the list iterator (by a call to the AbstractListIterator.next() method).
      Throws:
      NullPointerException - if the given list is null.
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).
  • Method Details

    • isIncluded

      protected boolean isIncluded(int index)
      Determines whether the item at the given index should be included. This version includes all indexes.
      Specified by:
      isIncluded in class AbstractListIterator<E,E>
      Parameters:
      index - The index of the item to check.
      Returns:
      true if the item at the given index should be included in the iteration, else false if it should be ignored.
    • getItem

      protected E getItem(int index)
      Retrieves an item representing the element at the given position in the list.
      Specified by:
      getItem in class AbstractListIterator<E,E>
      Parameters:
      index - The list index
      Returns:
      An item representing the element at the given index in the list
      Throws:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
    • setItem

      protected E setItem(int index, E item)
      Sets the element at the given position in the list.
      Specified by:
      setItem in class AbstractListIterator<E,E>
      Parameters:
      index - The list index
      item - The item representing the element to be stored at the specified position.
      Returns:
      An item representing the element previously at the specified position.
      Throws:
      UnsupportedOperationException - if the AbstractListIterator.set(Object) operation is not supported by this list iterator.
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
    • addItem

      protected void addItem(int index, E item)
      Inserts an element at the given position in the list.
      Specified by:
      addItem in class AbstractListIterator<E,E>
      Parameters:
      index - The list index
      item - The item representing the element to be inserted at the specified position.
      Throws:
      UnsupportedOperationException - if the AbstractListIterator.add(Object) operation is not supported by this list iterator.
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).