Class LoopingListIterator<E>
- Type Parameters:
- E- the type of elements returned by this iterator.
- All Implemented Interfaces:
- Iterator<E>,- ListIterator<E>,- OrderedIterator<E>,- ResettableIterator<E>,- ResettableListIterator<E>
 The iterator will loop continuously around the provided list,
 unless there are no elements in the collection to begin with, or
 all of the elements have been removed.
 
Concurrent modifications are not directly supported, and for most collection implementations will throw a ConcurrentModificationException.
- Since:
- 3.2
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidInserts the specified element into the underlying list.booleanhasNext()Returns whether this iterator has any more elements.booleanReturns whether this iterator has any more previous elements.next()Returns the next object in the list.intReturns the index of the element that would be returned by a subsequent call tonext().previous()Returns the previous object in the list.intReturns the index of the element that would be returned by a subsequent call toprevious().voidremove()Removes the previously retrieved item from the underlying list.voidreset()Resets the iterator back to the start of the list.voidReplaces the last element that was returned bynext()orprevious().intsize()Gets the size of the list underlying the iterator.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.IteratorforEachRemaining
- 
Constructor Details- 
LoopingListIteratorConstructor that wraps a list.There is no way to reset a ListIterator instance without recreating it from the original source, so the List must be passed in and a reference to it held. - Parameters:
- list- the list to wrap
- Throws:
- NullPointerException- if the list is null
 
 
- 
- 
Method Details- 
addInserts the specified element into the underlying list.The element is inserted before the next element that would be returned by next(), if any, and after the next element that would be returned byprevious(), if any.This feature is only supported if the underlying list's List.listIterator()method returns an implementation that supports it.- Specified by:
- addin interface- ListIterator<E>
- Parameters:
- obj- the element to insert
- Throws:
- UnsupportedOperationException- if the add method is not supported by the iterator implementation of the underlying list
 
- 
hasNextReturns whether this iterator has any more elements.Returns false only if the list originally had zero elements, or all elements have been removed.
- 
hasPreviousReturns whether this iterator has any more previous elements.Returns false only if the list originally had zero elements, or all elements have been removed.- Specified by:
- hasPreviousin interface- ListIterator<E>
- Specified by:
- hasPreviousin interface- OrderedIterator<E>
- Returns:
- trueif there are more elements
 
- 
nextReturns the next object in the list.If at the end of the list, returns the first element. - Specified by:
- nextin interface- Iterator<E>
- Specified by:
- nextin interface- ListIterator<E>
- Returns:
- the object after the last element returned
- Throws:
- NoSuchElementException- if there are no elements in the list
 
- 
nextIndexReturns the index of the element that would be returned by a subsequent call tonext().As would be expected, if the iterator is at the physical end of the underlying list, 0 is returned, signifying the beginning of the list. - Specified by:
- nextIndexin interface- ListIterator<E>
- Returns:
- the index of the element that would be returned if next() were called
- Throws:
- NoSuchElementException- if there are no elements in the list
 
- 
previousReturns the previous object in the list.If at the beginning of the list, return the last element. Note that in this case, traversal to find that element takes linear time. - Specified by:
- previousin interface- ListIterator<E>
- Specified by:
- previousin interface- OrderedIterator<E>
- Returns:
- the object before the last element returned
- Throws:
- NoSuchElementException- if there are no elements in the list
 
- 
previousIndexReturns the index of the element that would be returned by a subsequent call toprevious().As would be expected, if at the iterator is at the physical beginning of the underlying list, the list's size minus one is returned, signifying the end of the list. - Specified by:
- previousIndexin interface- ListIterator<E>
- Returns:
- the index of the element that would be returned if previous() were called
- Throws:
- NoSuchElementException- if there are no elements in the list
 
- 
removeRemoves the previously retrieved item from the underlying list.This feature is only supported if the underlying list's List.iterator()method returns an implementation that supports it.This method can only be called after at least one next()orprevious()method call. After a removal, the remove method may not be called again until anothernext()orprevious()has been performed. If thereset()is called, then remove may not be called untilnext()orprevious()is called again.- Specified by:
- removein interface- Iterator<E>
- Specified by:
- removein interface- ListIterator<E>
- Throws:
- UnsupportedOperationException- if the remove method is not supported by the iterator implementation of the underlying list
 
- 
resetResets the iterator back to the start of the list.- Specified by:
- resetin interface- ResettableIterator<E>
 
- 
setReplaces the last element that was returned bynext()orprevious().This feature is only supported if the underlying list's List.listIterator()method returns an implementation that supports it.- Specified by:
- setin interface- ListIterator<E>
- Parameters:
- obj- the element with which to replace the last element returned
- Throws:
- UnsupportedOperationException- if the set method is not supported by the iterator implementation of the underlying list
 
- 
size
 
-