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>
A default list iterator that can iterate over a given list.
- Author:
- Garret Wilson
-
Constructor Summary
ConstructorDescriptionDefaultListIterator
(List<E> list) List constructor starting at the first index.DefaultListIterator
(List<E> list, int index) List and index constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Inserts an element at the given position in the list.protected E
getItem
(int index) Retrieves an item representing the element at the given position in the list.protected boolean
isIncluded
(int index) Determines whether the item at the given index should be included.protected E
Sets the element at the given position in the list.Methods inherited from class com.globalmentor.collections.iterators.AbstractListIterator
add, getList, getNextIncludedIndex, getPreviousIncludedIndex, hasNext, hasPrevious, next, nextIndex, previous, previousIndex, remove, set, updateIncludedIndexes
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
-
Constructor Details
-
DefaultListIterator
List constructor starting at the first index.- Parameters:
list
- The list over which to iterate.- Throws:
NullPointerException
- if the given list isnull
.
-
DefaultListIterator
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 theAbstractListIterator.next()
method).- Throws:
NullPointerException
- if the given list isnull
.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 classAbstractListIterator<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, elsefalse
if it should be ignored.
-
getItem
Retrieves an item representing the element at the given position in the list.- Specified by:
getItem
in classAbstractListIterator<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
Sets the element at the given position in the list.- Specified by:
setItem
in classAbstractListIterator<E,
E> - Parameters:
index
- The list indexitem
- 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 theAbstractListIterator.set(Object)
operation is not supported by this list iterator.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >=size()
).
-
addItem
Inserts an element at the given position in the list.- Specified by:
addItem
in classAbstractListIterator<E,
E> - Parameters:
index
- The list indexitem
- The item representing the element to be inserted at the specified position.- Throws:
UnsupportedOperationException
- if theAbstractListIterator.add(Object)
operation is not supported by this list iterator.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >size()
).
-