package lists; /** * An iterator for lists that allows the programmer * to traverse the list in either direction, modify * the list during iteration, and obtain the iterator's * current position in the list. */ public interface ListIterator<E> extends Iterator<E> { /** * Returns true if this list iterator has more elements when * traversing the list in the forward direction. */ boolean hasNext(); /** * Returns the next element in the list and advances the cursor position. * This method may be called repeatedly to iterate through the list, * or intermixed with calls to previous to go back and forth. */ E next(); /** * Returns true if this list iterator has more elements when * traversing the list in the reverse direction. */ boolean hasPrevious(); /** * Returns the previous element in the list and moves the cursor * position backwards. This method may be called repeatedly to * iterate through the list backwards, or intermixed with calls to * next to go back and forth. */ E previous(); /** * Returns the index of the element that would be returned by a * subsequent call to next. (Returns list size if the list * iterator is at the end of the list.) */ int nextIndex(); /** * Returns the index of the element that would be returned by a * subsequent call to previous. (Returns -1 if the list * iterator is at the beginning of the list.) */ int previousIndex(); /** * Removes from the list the last element that was returned by * next or previous (optional operation). This call can * only be made once per call to next or previous. */ void remove(); /** * Replaces the last element returned by next or * previous with the specified element (optional operation). * This call can be made only if neither remove nor * add have been called after the last call to next or previous. */ void set(E e); /** * Inserts the specified element into the list (optional operation). * The element is inserted immediately before the next element that * would be returned by next, if any, and after the next * element that would be returned by previous, if any. (If the * list contains no elements, the new element becomes the sole element * cursor: a subsequent call to next would be unaffected, and a * subsequent call to previous would return the new element. */ void add(E e); }