private class DoublyLinkedListIterator implements ListIterator<E> {
private DoublyLinkedList.Node<E> nextNode, prevNode, lastReturnedNode; // node that will be returned using next and prev respectively
private int nextIndex; // Index of the next element
private int expectedModCount; // Expected number of modifications = modCount;
public DoublyLinkedListIterator() {
this.prevNode = header;
this.nextNode = header.getNext();
lastReturnedNode = null;
nextIndex = 0;
expectedModCount = modCount;
}
final void checkForComodification() { // invalidate iterator on list modification outside the iterator
if (modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
}
@Override
public boolean hasNext() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public E next() throws NoSuchElementException {
checkForComodification();
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean hasPrevious() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public E previous() throws NoSuchElementException {
checkForComodification();
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int nextIndex() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int previousIndex() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void remove() throws NoSuchElementException {
checkForComodification();
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void set(E e) throws NoSuchElementException {
if (lastReturnedNode == null) {
throw new NoSuchElementException();
}
checkForComodification();
lastReturnedNode.setElement(e);
}
@Override
public void add(E e) {
checkForComodification();
throw new UnsupportedOperationException("Not supported yet.");
}
} //----------- end of inner DoublyLinkedListIterator class ----------
//---------------- Iterable implementation ----------------