Patched ArrayIterator so that it can work with any type of array, not just Object[] instances

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2001-08-23 09:05:26 +00:00
parent 74abd625bc
commit ea64efd6dc
1 changed files with 8 additions and 7 deletions

View File

@ -7,6 +7,7 @@
*/
package org.apache.commons.collections;
import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.NoSuchElementException;
@ -15,32 +16,32 @@ import java.util.NoSuchElementException;
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author Mauricio S. Moura
* @
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
*/
public class ArrayIterator implements Iterator {
private Object[] array;
private Object array;
private int index = 0;
public ArrayIterator() {
}
public ArrayIterator(Object[] array) {
public ArrayIterator(Object array) {
this.array = array;
}
// Iterator interface
//-------------------------------------------------------------------------
public boolean hasNext() {
return (index < array.length);
return index < Array.getLength( array );
}
public Object next() {
if(!hasNext()) {
throw new NoSuchElementException();
}
return array[ index++ ];
return Array.get( array, index++ );
}
public void remove() {
@ -49,11 +50,11 @@ public class ArrayIterator implements Iterator {
// Properties
//-------------------------------------------------------------------------
public Object[] getArray() {
public Object getArray() {
return array;
}
public void setArray( Object[] array ) {
public void setArray( Object array ) {
this.array = array;
this.index = -1;
}