public Iterator descendingIterator()

in src/main/java/com/twitter/whiskey/util/LinkedHashDeque.java [297:326]


    public Iterator<E> descendingIterator() {
        return new Iterator<E>() {
            Node<E> current = tail;
            int sentinel = mutations;
            E removeable = null;

            @Override
            public boolean hasNext() {
                if (sentinel != mutations) throw new ConcurrentModificationException();
                return current != head;
            }

            @Override
            public E next() {
                if (!hasNext()) throw new NoSuchElementException();
                removeable = current.e;
                current = map.get(removeable);
                return removeable;
            }

            @Override
            public void remove() {
                if (sentinel != mutations) throw new ConcurrentModificationException();
                if (removeable == null) throw new IllegalStateException();
                LinkedHashDeque.this.remove(removeable);
                sentinel++;
                removeable = null;
            }
        };
    }