collections.immutable.ArrayIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of collections Show documentation
Show all versions of collections Show documentation
Java code for the collections package.
The newest version!
package collections.immutable;
import java.lang.reflect.Array;
import java.util.Iterator;
//Fast iterable of an array.
final class ArrayIterable implements Iterable {
final Object array;
public ArrayIterable(Object array) {
super();
this.array = array;
}
@Override
public Iterator iterator() {
return new ArrayIterator();
}
final class ArrayIterator implements Iterator {
int i = 0;
public ArrayIterator() {
super();
}
@Override
public boolean hasNext() {
return i < Array.getLength(array);
}
@Override
public E next() {
@SuppressWarnings("unchecked")
E e = (E)Array.get(array, i++);
return e;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}