Package net.cscott.jutil
Class UnmodifiableListIterator<E>
java.lang.Object
net.cscott.jutil.UnmodifiableListIterator<E>
- All Implemented Interfaces:
Iterator<E>,ListIterator<E>
UnmodifiableListIterator is an abstract superclass to
save you the trouble of implementing the remove(),
add(Object) and set(Object) methods over and over again
for those list iterators which don't implement them. The name's a
bit clunky, but fits with the JDK naming in
Collections and such.- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAlways throws anUnsupportedOperationException.abstract booleanhasNext()Returnstrueif the list iterator has more elements in the forward direction.abstract booleanReturnstrueif the list iterator has more elements in the reverse direction.abstract Enext()Returns the next element in the list.abstract intReturns the index of the element that would be returned by a subsequent call tonext().abstract Eprevious()Returns the previous element in the list.intReturns the index of the element that would be returned by a subsequent call toprevious().final voidremove()Always throws anUnsupportedOperationException.final voidAlways throws anUnsupportedOperationException.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
UnmodifiableListIterator
public UnmodifiableListIterator()
-
-
Method Details
-
hasNext
public abstract boolean hasNext()Returnstrueif the list iterator has more elements in the forward direction. -
next
Returns the next element in the list. This method may be called repeatedly to iterate through the list, or intermixed with calls toprevious()to go back and forth. (Note that alternating calls tonext()andprevious()will return the same element repeatedly.)- Specified by:
nextin interfaceIterator<E>- Specified by:
nextin interfaceListIterator<E>- Throws:
NoSuchElementException- if the iteration has no next element.
-
hasPrevious
public abstract boolean hasPrevious()Returnstrueif the list iterator has more elements in the reverse direction.- Specified by:
hasPreviousin interfaceListIterator<E>
-
previous
Returns the previous element in the list. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls tonext()to go back and forth. (Note that alternating calls tonext()andprevious()will return the same element repeatedly.)- Specified by:
previousin interfaceListIterator<E>- Throws:
NoSuchElementException- if the iteration has no previous element.
-
nextIndex
public abstract int nextIndex()Returns the index of the element that would be returned by a subsequent call tonext(). (Returns list size if the list iterator is at the end of the list.)- Specified by:
nextIndexin interfaceListIterator<E>
-
previousIndex
public int previousIndex()Returns the index of the element that would be returned by a subsequent call toprevious(). (Returns -1 if the list iterator is at the beginning of the list.)- Specified by:
previousIndexin interfaceListIterator<E>
-
remove
public final void remove()Always throws anUnsupportedOperationException.- Specified by:
removein interfaceIterator<E>- Specified by:
removein interfaceListIterator<E>- Throws:
UnsupportedOperationException- always.
-
set
Always throws anUnsupportedOperationException.- Specified by:
setin interfaceListIterator<E>- Throws:
UnsupportedOperationException- always.
-
add
Always throws anUnsupportedOperationException.- Specified by:
addin interfaceListIterator<E>- Throws:
UnsupportedOperationException- always.
-