Class ListIteratorWrapper<E>
- java.lang.Object
-
- org.apache.openjpa.lib.util.collections.ListIteratorWrapper<E>
-
- All Implemented Interfaces:
java.util.Iterator<E>,java.util.ListIterator<E>,OrderedIterator<E>,ResettableIterator<E>,ResettableListIterator<E>
public class ListIteratorWrapper<E> extends java.lang.Object implements ResettableListIterator<E>
Converts anIteratorinto aResettableListIterator. For plainIterators this is accomplished by caching the returned elements. This class can also be used to simply addResettableIteratorfunctionality to a givenListIterator.The
ListIteratorinterface has additional useful methods for navigation -previous()and the index methods. This class allows a regularIteratorto behave as aListIterator. It achieves this by building a list internally of as the underlying iterator is traversed.The optional operations of
ListIteratorare not supported for plainIterators.This class implements ResettableListIterator from Commons Collections 3.2.
- Since:
- 2.1
-
-
Constructor Summary
Constructors Constructor Description ListIteratorWrapper(java.util.Iterator<? extends E> iterator)Constructs a newListIteratorWrapperthat will wrap the given iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(E obj)ThrowsUnsupportedOperationExceptionunless the underlyingIteratoris aListIterator.booleanhasNext()Returns true if there are more elements in the iterator.booleanhasPrevious()Returns true if there are previous elements in the iterator.Enext()Returns the next element from the iterator.intnextIndex()Returns the index of the next element.Eprevious()Returns the previous element.intpreviousIndex()Returns the index of the previous element.voidremove()ThrowsUnsupportedOperationExceptionifprevious()has ever been called.voidreset()Resets this iterator back to the position at which the iterator was created.voidset(E obj)ThrowsUnsupportedOperationExceptionunless the underlyingIteratoris aListIterator.
-
-
-
Constructor Detail
-
ListIteratorWrapper
public ListIteratorWrapper(java.util.Iterator<? extends E> iterator)
Constructs a newListIteratorWrapperthat will wrap the given iterator.- Parameters:
iterator- the iterator to wrap- Throws:
java.lang.NullPointerException- if the iterator is null
-
-
Method Detail
-
add
public void add(E obj) throws java.lang.UnsupportedOperationException
ThrowsUnsupportedOperationExceptionunless the underlyingIteratoris aListIterator.- Specified by:
addin interfacejava.util.ListIterator<E>- Parameters:
obj- the object to add- Throws:
java.lang.UnsupportedOperationException- if the underlying iterator is not of typeListIterator
-
hasNext
public boolean hasNext()
Returns true if there are more elements in the iterator.
-
hasPrevious
public boolean hasPrevious()
Returns true if there are previous elements in the iterator.- Specified by:
hasPreviousin interfacejava.util.ListIterator<E>- Specified by:
hasPreviousin interfaceOrderedIterator<E>- Returns:
- true if there are previous elements
-
next
public E next() throws java.util.NoSuchElementException
Returns the next element from the iterator.
-
nextIndex
public int nextIndex()
Returns the index of the next element.- Specified by:
nextIndexin interfacejava.util.ListIterator<E>- Returns:
- the index of the next element
-
previous
public E previous() throws java.util.NoSuchElementException
Returns the previous element.- Specified by:
previousin interfacejava.util.ListIterator<E>- Specified by:
previousin interfaceOrderedIterator<E>- Returns:
- the previous element
- Throws:
java.util.NoSuchElementException- if there are no previous elements
-
previousIndex
public int previousIndex()
Returns the index of the previous element.- Specified by:
previousIndexin interfacejava.util.ListIterator<E>- Returns:
- the index of the previous element
-
remove
public void remove() throws java.lang.UnsupportedOperationExceptionThrowsUnsupportedOperationExceptionifprevious()has ever been called.
-
set
public void set(E obj) throws java.lang.UnsupportedOperationException
ThrowsUnsupportedOperationExceptionunless the underlyingIteratoris aListIterator.- Specified by:
setin interfacejava.util.ListIterator<E>- Parameters:
obj- the object to set- Throws:
java.lang.UnsupportedOperationException- if the underlying iterator is not of typeListIterator
-
reset
public void reset()
Resets this iterator back to the position at which the iterator was created.- Specified by:
resetin interfaceResettableIterator<E>- Since:
- 3.2
-
-