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 ofListIteratorthat works from a list of elements and a set of features to support (from the enclosingAbstractIteratorTesterinstance). Instead of throwing exceptions likeNoSuchElementExceptionat the appropriate times, it throwsAbstractIteratorTester.PermittedMetaExceptioninstances, 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 eitherIllegalStateExceptionorUnsupportedOperationException. Note that iterator implementations should always throw one of the exceptions in aPermittedExceptionsinstance, sincePermittedExceptionsis 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>nextElementsThe elements to be returned by future calls tonext(), with the first at the top of the stack.(package private) java.util.Stack<E>previousElementsThe elements to be returned by future calls toprevious(), with the first at the top of the stack.(package private) java.util.Stack<E>stackWithLastReturnedElementAtTopnextElementsifnext()was called more recently thenprevious,previousElementsif the reverse is true, or -- overriding both of these --nullifremove()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 voidadd(E e)private java.util.List<E>getElements()booleanhasNext()booleanhasPrevious()Enext()intnextIndex()Eprevious()intpreviousIndex()(package private) voidpromoteToNext(E e)Moves the given element from its current position innextElementsto the top of the stack so that it is returned by the next call toIterator.next().voidremove()voidset(E e)private voidthrowIfInvalid(IteratorFeature methodFeature)private EtransferElement(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
nextElementsifnext()was called more recently thenprevious,previousElementsif the reverse is true, or -- overriding both of these --nullifremove()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:
hasPreviousin interfacejava.util.ListIterator<E>
-
next
public E next()
-
nextIndex
public int nextIndex()
- Specified by:
nextIndexin interfacejava.util.ListIterator<E>
-
previousIndex
public int previousIndex()
- Specified by:
previousIndexin interfacejava.util.ListIterator<E>
-
remove
public void remove()
-
promoteToNext
void promoteToNext(E e)
Moves the given element from its current position innextElementsto 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()
-
-