Class AbstractIteratorTester.MultiExceptionListIterator
java.lang.Object
com.google.common.collect.testing.AbstractIteratorTester.MultiExceptionListIterator
- All Implemented Interfaces:
Iterator<E>
,ListIterator<E>
- Enclosing class:
AbstractIteratorTester<E,
I extends Iterator<E>>
protected final class AbstractIteratorTester.MultiExceptionListIterator
extends Object
implements ListIterator<E>
Quasi-implementation of
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
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe elements to be returned by future calls tonext()
, with the first at the top of the stack.The elements to be returned by future calls toprevious()
, with the first at the top of the stack.nextElements
ifnext()
was called more recently thenprevious
,previousElements
if the reverse is true, or -- overriding both of these --null
ifremove()
oradd()
has been called more recently than either. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
hasNext()
boolean
next()
int
previous()
int
(package private) void
promoteToNext
(E e) Moves the given element from its current position innextElements
to the top of the stack so that it is returned by the next call toIterator.next()
.void
remove()
void
private void
throwIfInvalid
(IteratorFeature methodFeature) private E
transferElement
(Stack<E> source, Stack<E> destination) 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 Details
-
nextElements
The elements to be returned by future calls tonext()
, with the first at the top of the stack. -
previousElements
The elements to be returned by future calls toprevious()
, with the first at the top of the stack. -
stackWithLastReturnedElementAtTop
nextElements
ifnext()
was called more recently thenprevious
,previousElements
if the reverse is true, or -- overriding both of these --null
ifremove()
oradd()
has been called more recently than either. We use this to determine which stack to pop from on a call toremove()
(or to pop from and push to on a call toset()
).
-
-
Constructor Details
-
MultiExceptionListIterator
-
-
Method Details
-
add
- Specified by:
add
in interfaceListIterator<E>
-
hasNext
public boolean hasNext() -
hasPrevious
public boolean hasPrevious()- Specified by:
hasPrevious
in interfaceListIterator<E>
-
next
-
nextIndex
public int nextIndex()- Specified by:
nextIndex
in interfaceListIterator<E>
-
previous
- Specified by:
previous
in interfaceListIterator<E>
-
previousIndex
public int previousIndex()- Specified by:
previousIndex
in interfaceListIterator<E>
-
remove
public void remove() -
set
- Specified by:
set
in interfaceListIterator<E>
-
promoteToNext
Moves the given element from its current position innextElements
to the top of the stack so that it is returned by the next call toIterator.next()
. If the element is not innextElements
, this method throws anAbstractIteratorTester.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.
-
transferElement
-
throwIfInvalid
-
getElements
-