Class AbstractLinkedList.LinkedListIterator
- java.lang.Object
-
- org.apache.commons.collections.list.AbstractLinkedList.LinkedListIterator
-
- All Implemented Interfaces:
Iterator
,ListIterator
,OrderedIterator
- Direct Known Subclasses:
AbstractLinkedList.LinkedSubListIterator
,CursorableLinkedList.Cursor
- Enclosing class:
- AbstractLinkedList
protected static class AbstractLinkedList.LinkedListIterator extends Object implements ListIterator, OrderedIterator
A list iterator over the linked list.
-
-
Field Summary
Fields Modifier and Type Field Description protected AbstractLinkedList.Node
current
The last node that was returned bynext()
orprevious()
.protected int
expectedModCount
The modification count that the list is expected to have.protected AbstractLinkedList.Node
next
The node that will be returned bynext()
.protected int
nextIndex
The index ofnext
.protected AbstractLinkedList
parent
The parent list
-
Constructor Summary
Constructors Modifier Constructor Description protected
LinkedListIterator(AbstractLinkedList parent, int fromIndex)
Create a ListIterator for a list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Object obj)
protected void
checkModCount()
Checks the modification count of the list is the value that this object expects.protected AbstractLinkedList.Node
getLastNodeReturned()
Gets the last node returned.boolean
hasNext()
boolean
hasPrevious()
Checks to see if there is a previous element that can be iterated to.Object
next()
int
nextIndex()
Object
previous()
Gets the previous element from the collection.int
previousIndex()
void
remove()
void
set(Object obj)
-
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
-
-
-
-
Field Detail
-
parent
protected final AbstractLinkedList parent
The parent list
-
next
protected AbstractLinkedList.Node next
The node that will be returned bynext()
. If this is equal toAbstractLinkedList.header
then there are no more values to return.
-
nextIndex
protected int nextIndex
The index ofnext
.
-
current
protected AbstractLinkedList.Node current
The last node that was returned bynext()
orprevious()
. Set tonull
ifnext()
orprevious()
haven't been called, or if the node has been removed withremove()
or a new node added withadd(Object)
. Should be accessed throughgetLastNodeReturned()
to enforce this behaviour.
-
expectedModCount
protected int expectedModCount
The modification count that the list is expected to have. If the list doesn't have this count, then aConcurrentModificationException
may be thrown by the operations.
-
-
Constructor Detail
-
LinkedListIterator
protected LinkedListIterator(AbstractLinkedList parent, int fromIndex) throws IndexOutOfBoundsException
Create a ListIterator for a list.- Parameters:
parent
- the parent listfromIndex
- the index to start at- Throws:
IndexOutOfBoundsException
-
-
Method Detail
-
checkModCount
protected void checkModCount()
Checks the modification count of the list is the value that this object expects.- Throws:
ConcurrentModificationException
- If the list's modification count isn't the value that was expected.
-
getLastNodeReturned
protected AbstractLinkedList.Node getLastNodeReturned() throws IllegalStateException
Gets the last node returned.- Throws:
IllegalStateException
- Ifnext()
orprevious()
haven't been called, or if the node has been removed withremove()
or a new node added withadd(Object)
.
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfaceIterator
- Specified by:
hasNext
in interfaceListIterator
-
next
public Object next()
- Specified by:
next
in interfaceIterator
- Specified by:
next
in interfaceListIterator
-
hasPrevious
public boolean hasPrevious()
Description copied from interface:OrderedIterator
Checks to see if there is a previous element that can be iterated to.- Specified by:
hasPrevious
in interfaceListIterator
- Specified by:
hasPrevious
in interfaceOrderedIterator
- Returns:
true
if the iterator has a previous element
-
previous
public Object previous()
Description copied from interface:OrderedIterator
Gets the previous element from the collection.- Specified by:
previous
in interfaceListIterator
- Specified by:
previous
in interfaceOrderedIterator
- Returns:
- the previous element in the iteration
-
nextIndex
public int nextIndex()
- Specified by:
nextIndex
in interfaceListIterator
-
previousIndex
public int previousIndex()
- Specified by:
previousIndex
in interfaceListIterator
-
remove
public void remove()
- Specified by:
remove
in interfaceIterator
- Specified by:
remove
in interfaceListIterator
-
set
public void set(Object obj)
- Specified by:
set
in interfaceListIterator
-
add
public void add(Object obj)
- Specified by:
add
in interfaceListIterator
-
-