jodd.util.collection.ArrayIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jodd-core Show documentation
Show all versions of jodd-core Show documentation
Jodd Core tools and utilities, including type converters, JDateTime, cache etc.
// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.
package jodd.util.collection;
import java.io.Serializable;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Iterator over an array.
*/
public class ArrayIterator implements Iterator, Serializable {
private E array[];
private int ndx;
private int endNdx;
public ArrayIterator(E array[]) {
this.array = array;
ndx = 0;
endNdx = array.length;
}
public ArrayIterator(E array[], int offset, int len) {
this.array = array;
ndx = offset;
endNdx = offset + len;
}
public boolean hasNext() {
return ndx < endNdx;
}
public E next() throws NoSuchElementException {
if (ndx < endNdx) {
ndx++;
return array[ndx - 1];
}
throw new NoSuchElementException();
}
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
}