反復子の実装を列挙子のインタフェイスで扱う #6

Iterableではないが、配列の要素を列挙するEnumerationも得られるといいかもしれない。

...snip
import java.util.NoSuchElementException;
...snip
    public static <E> Enumeration<E> enumeration(final E[] array) {
        return new Enumeration<E>() {
            private int index = 0;
            public boolean hasMoreElements() {
                return index < array.length;
            }
            public E nextElement() {
                if (! hasMoreElements()) throw new NoSuchElementException();
                return array[index++];
            }
        };
    }
...snip

配列が与えられているときにjava.util.Arrays.asList()等でわざわざList等のCollectionにしてからEnumerationを得る手間が省ける。