All Downloads are FREE. Search and download functionalities are using the official Maven repository.

collections.immutable.ArrayIterable Maven / Gradle / Ivy

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();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy