public Iterator iterator()

in src/main/java/com/twitter/whiskey/util/LinkedHashDeque.java [265:294]


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

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

            @Override
            public E next() {
                if (!hasNext()) throw new NoSuchElementException();
                current = current.next;
                removeable = current.e;
                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;
            }
        };
    }