Class ListIteratorDecorator<E>
java.lang.Object
com.globalmentor.collections.iterators.AbstractIteratorDecorator<E>
com.globalmentor.collections.iterators.IteratorDecorator<E>
com.globalmentor.collections.iterators.ListIteratorDecorator<E>
- All Implemented Interfaces:
Enumeration<E>
,Iterator<E>
,ListIterator<E>
- Direct Known Subclasses:
AbstractConverterList.ConverterListIterator
A list iterator that wraps an existing list iterator, providing access through the
ListIterator
interface.- Author:
- Garret Wilson
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ListIterator<E>
The list iterator this class decorates. -
Constructor Summary
ConstructorDescriptionListIteratorDecorator
(ListIterator<E> listIterator) List iterator constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts the specified element into the list (optional operation).boolean
Returnstrue
if this list iterator has more elements when traversing the list in the reverse direction.int
Returns the index of the element that would be returned by a subsequent call tonext
.previous()
Returns the previous element in the list.int
Returns the index of the element that would be returned by a subsequent call toprevious
.void
Replaces the last element returned bynext
orprevious
with the specified element (optional operation).Methods inherited from class com.globalmentor.collections.iterators.IteratorDecorator
getIterator
Methods inherited from class com.globalmentor.collections.iterators.AbstractIteratorDecorator
hasMoreElements, hasNext, next, nextElement, remove
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
Methods inherited from interface java.util.ListIterator
hasNext, next, remove
-
Field Details
-
listIterator
The list iterator this class decorates.
-
-
Constructor Details
-
ListIteratorDecorator
List iterator constructor.- Parameters:
listIterator
- The list iterator this list iterator should decorate.- Throws:
NullPointerException
- if the given iterator isnull
.
-
-
Method Details
-
hasPrevious
public boolean hasPrevious()Returnstrue
if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returnstrue
ifprevious
would return an element rather than throwing an exception.)- Specified by:
hasPrevious
in interfaceListIterator<E>
- Returns:
true
if the list iterator has more elements when traversing the list in the reverse direction.
-
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:
previous
in interfaceListIterator<E>
- Returns:
- the previous element in the list.
- Throws:
NoSuchElementException
- if the iteration has no previous element.
-
nextIndex
public 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:
nextIndex
in interfaceListIterator<E>
- Returns:
- the index of the element that would be returned by a subsequent call to
next
, or list size if list iterator is at end of list.
-
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:
previousIndex
in interfaceListIterator<E>
- Returns:
- the index of the element that would be returned by a subsequent call to
previous
, or -1 if list iterator is at beginning of list.
-
set
Replaces the last element returned bynext
orprevious
with the specified element (optional operation). This call can be made only if neitherListIterator.remove
norListIterator.add
have been called after the last call tonext
orprevious
.- Specified by:
set
in interfaceListIterator<E>
- Parameters:
o
- the element with which to replace the last element returned bynext
orprevious
.- Throws:
UnsupportedOperationException
- if theset
operation is not supported by this list iterator.ClassCastException
- if the class of the specified element prevents it from being added to this list.IllegalArgumentException
- if some aspect of the specified element prevents it from being added to this list.IllegalStateException
- if neithernext
norprevious
have been called, orremove
oradd
have been called after the last call tonext
orprevious
.
-
add
Inserts the specified element into the list (optional operation). The element is inserted immediately before the next element that would be returned bynext
, if any, and after the next element that would be returned byprevious
, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call tonext
would be unaffected, and a subsequent call toprevious
would return the new element. (This call increases by one the value that would be returned by a call tonextIndex
orpreviousIndex
.)- Specified by:
add
in interfaceListIterator<E>
- Parameters:
o
- the element to insert.- Throws:
UnsupportedOperationException
- if theadd
method is not supported by this list iterator.ClassCastException
- if the class of the specified element prevents it from being added to this list.IllegalArgumentException
- if some aspect of this element prevents it from being added to this list.
-