package co.phoenixlab.common.lang;

import java.util.ListIterator;

/**
 * Provides a reversed view of a ListIterator, starting from the last element.
 * @param <E>
 */
public class ReverseListIterator<E> implements ListIterator<E> {

    private final ListIterator<E> parent;

    public ReverseListIterator(ListIterator<E> parent) {
        this.parent = parent;
        //  Wind the iterator to the end
        while (parent.hasNext()) {
            parent.next();
        }
    }

    @Override
    public boolean hasNext() {
        return parent.hasPrevious();
    }

    @Override
    public E next() {
        return parent.previous();
    }

    @Override
    public boolean hasPrevious() {
        return parent.hasNext();
    }

    @Override
    public E previous() {
        return parent.next();
    }

    @Override
    public int nextIndex() {
        return parent.previousIndex();
    }

    @Override
    public int previousIndex() {
        return parent.nextIndex();
    }

    @Override
    public void remove() {
        parent.remove();
    }

    @Override
    public void set(E e) {
        parent.set(e);
    }

    @Override
    public void add(E e) {
        parent.add(e);
    }
}

@@ -46,27 +46,151 @@
 va.util.
-List
 Iterato
+r;%0Aimport java.util.ListIterator;%0Aimport java.util.Spliterator;%0Aimport java.util.Spliterators;%0Aimport java.util.function.Consume
 r;%0A%0A/**%0A
@@ -348,16 +348,29 @@
 rator%3CE%3E
+, Iterable%3CE%3E
  %7B%0A%0A    
@@ -1338,11 +1338,361 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public Iterator%3CE%3E iterator() %7B%0A        return this;%0A    %7D%0A%0A    @Override%0A    public void forEach(Consumer%3C? super E%3E action) %7B%0A        while (hasNext()) %7B%0A            action.accept(next());%0A        %7D%0A    %7D%0A%0A    @Override%0A    public Spliterator%3CE%3E spliterator() %7B%0A        return Spliterators.spliteratorUnknownSize(this, 0);%0A    %7D
 %0A%7D%0A

Implement iterable for use in efor loops