jodd.util.collection.ArrayEnumeration 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.Enumeration;
import java.util.NoSuchElementException;
/**
* Enumeration over an array.
*/
public class ArrayEnumeration implements Enumeration, Serializable {
private E array[];
private int ndx;
private int endNdx;
public ArrayEnumeration(E arr[]) {
this(arr, 0, arr.length);
}
public ArrayEnumeration(E arr[], int offset, int length) {
array = arr;
ndx = offset;
this.endNdx = offset + length;
}
public boolean hasMoreElements() {
return ndx < endNdx;
}
public E nextElement() throws NoSuchElementException {
if (ndx < endNdx) {
return array[ndx++];
}
throw new NoSuchElementException();
}
}