protected final class AbstractIteratorTester.MultiExceptionListIterator
extends java.lang.Object
implements java.util.ListIterator<E>
ListIterator
that works from a list of elements and a set of
features to support (from the enclosing AbstractIteratorTester
instance). Instead of
throwing exceptions like NoSuchElementException
at the appropriate times, it throws
AbstractIteratorTester.PermittedMetaException
instances, which wrap a set of all exceptions that the iterator
could throw during the invocation of that method. This is necessary because, e.g., a call to
iterator().remove()
of an unmodifiable list could throw either IllegalStateException
or UnsupportedOperationException
. Note that iterator
implementations should always throw one of the exceptions in a PermittedExceptions
instance, since PermittedExceptions
is thrown only when a method call is invalid.
This class is accessible but not supported in GWT as it references AbstractIteratorTester.PermittedMetaException
.
Modifier and Type | Field and Description |
---|---|
(package private) java.util.Stack<E> |
nextElements
The elements to be returned by future calls to
next() , with the first at the top of
the stack. |
(package private) java.util.Stack<E> |
previousElements
The elements to be returned by future calls to
previous() , with the first at the top
of the stack. |
(package private) java.util.Stack<E> |
stackWithLastReturnedElementAtTop
nextElements if next() was called more recently then previous ,
previousElements if the reverse is true, or -- overriding both of these -- null if remove() or add() has been called more recently than either. |
Constructor and Description |
---|
MultiExceptionListIterator(java.util.List<E> expectedElements) |
Modifier and Type | Method and Description |
---|---|
void |
add(E e) |
private java.util.List<E> |
getElements() |
boolean |
hasNext() |
boolean |
hasPrevious() |
E |
next() |
int |
nextIndex() |
E |
previous() |
int |
previousIndex() |
(package private) void |
promoteToNext(E e)
Moves the given element from its current position in
nextElements to the top of the
stack so that it is returned by the next call to Iterator.next() . |
void |
remove() |
void |
set(E e) |
private void |
throwIfInvalid(IteratorFeature methodFeature) |
private E |
transferElement(java.util.Stack<E> source,
java.util.Stack<E> destination) |
final java.util.Stack<E> nextElements
next()
, with the first at the top of
the stack.final java.util.Stack<E> previousElements
previous()
, with the first at the top
of the stack.java.util.Stack<E> stackWithLastReturnedElementAtTop
nextElements
if next()
was called more recently then previous
,
previousElements
if the reverse is true, or -- overriding both of these -- null
if remove()
or add()
has been called more recently than either. We use
this to determine which stack to pop from on a call to remove()
(or to pop from and
push to on a call to set()
.MultiExceptionListIterator(java.util.List<E> expectedElements)
public boolean hasNext()
public boolean hasPrevious()
hasPrevious
in interface java.util.ListIterator<E>
public E next()
public int nextIndex()
nextIndex
in interface java.util.ListIterator<E>
public int previousIndex()
previousIndex
in interface java.util.ListIterator<E>
public void remove()
void promoteToNext(E e)
nextElements
to the top of the
stack so that it is returned by the next call to Iterator.next()
. If the element is
not in nextElements
, this method throws an AbstractIteratorTester.UnknownElementException
.
This method is used when testing iterators without a known ordering. We poll the target iterator's next element and pass it to the reference iterator through this method so it can return the same element. This enables the assertion to pass and the reference iterator to properly update its state.
private E transferElement(java.util.Stack<E> source, java.util.Stack<E> destination)
private void throwIfInvalid(IteratorFeature methodFeature)
private java.util.List<E> getElements()