Class AbstractIteratorTester.MultiExceptionListIterator
- java.lang.Object
-
- com.google.common.collect.testing.AbstractIteratorTester.MultiExceptionListIterator
-
- All Implemented Interfaces:
java.util.Iterator<E>
,java.util.ListIterator<E>
- Enclosing class:
- AbstractIteratorTester<E,I extends java.util.Iterator<E>>
protected final class AbstractIteratorTester.MultiExceptionListIterator extends java.lang.Object implements java.util.ListIterator<E>
Quasi-implementation ofListIterator
that works from a list of elements and a set of features to support (from the enclosingAbstractIteratorTester
instance). Instead of throwing exceptions likeNoSuchElementException
at the appropriate times, it throwsAbstractIteratorTester.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 toiterator().remove()
of an unmodifiable list could throw eitherIllegalStateException
orUnsupportedOperationException
. Note that iterator implementations should always throw one of the exceptions in aPermittedExceptions
instance, sincePermittedExceptions
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
Fields Modifier and Type Field Description (package private) java.util.Stack<E>
nextElements
The elements to be returned by future calls tonext()
, with the first at the top of the stack.(package private) java.util.Stack<E>
previousElements
The elements to be returned by future calls toprevious()
, with the first at the top of the stack.(package private) java.util.Stack<E>
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.
-
Constructor Summary
Constructors Constructor Description MultiExceptionListIterator(java.util.List<E> expectedElements)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 innextElements
to the top of the stack so that it is returned by the next call toIterator.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)
-
-
-
Field Detail
-
nextElements
final java.util.Stack<E> nextElements
The elements to be returned by future calls tonext()
, with the first at the top of the stack.
-
previousElements
final java.util.Stack<E> previousElements
The elements to be returned by future calls toprevious()
, with the first at the top of the stack.
-
stackWithLastReturnedElementAtTop
java.util.Stack<E> 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 Detail
-
MultiExceptionListIterator
MultiExceptionListIterator(java.util.List<E> expectedElements)
-
-
Method Detail
-
hasNext
public boolean hasNext()
-
hasPrevious
public boolean hasPrevious()
- Specified by:
hasPrevious
in interfacejava.util.ListIterator<E>
-
next
public E next()
-
nextIndex
public int nextIndex()
- Specified by:
nextIndex
in interfacejava.util.ListIterator<E>
-
previousIndex
public int previousIndex()
- Specified by:
previousIndex
in interfacejava.util.ListIterator<E>
-
remove
public void remove()
-
promoteToNext
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()
. 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
private E transferElement(java.util.Stack<E> source, java.util.Stack<E> destination)
-
throwIfInvalid
private void throwIfInvalid(IteratorFeature methodFeature)
-
getElements
private java.util.List<E> getElements()
-
-