Class 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 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

      Fields 
      Modifier and Type Field 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.
    • Field Detail

      • nextElements

        final java.util.Stack<E> nextElements
        The elements to be returned by future calls to next(), with the first at the top of the stack.
      • previousElements

        final java.util.Stack<E> previousElements
        The elements to be returned by future calls to previous(), with the first at the top of the stack.
      • stackWithLastReturnedElementAtTop

        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().
    • Constructor Detail

      • MultiExceptionListIterator

        MultiExceptionListIterator​(java.util.List<E> expectedElements)
    • Method Detail

      • add

        public void add​(E e)
        Specified by:
        add in interface java.util.ListIterator<E>
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<E>
        Specified by:
        hasNext in interface java.util.ListIterator<E>
      • hasPrevious

        public boolean hasPrevious()
        Specified by:
        hasPrevious in interface java.util.ListIterator<E>
      • next

        public E next()
        Specified by:
        next in interface java.util.Iterator<E>
        Specified by:
        next in interface java.util.ListIterator<E>
      • nextIndex

        public int nextIndex()
        Specified by:
        nextIndex in interface java.util.ListIterator<E>
      • previous

        public E previous()
        Specified by:
        previous in interface java.util.ListIterator<E>
      • previousIndex

        public int previousIndex()
        Specified by:
        previousIndex in interface java.util.ListIterator<E>
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<E>
        Specified by:
        remove in interface java.util.ListIterator<E>
      • set

        public void set​(E e)
        Specified by:
        set in interface java.util.ListIterator<E>
      • promoteToNext

        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(). 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.

      • 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()