1 3 package jodd.util.collection; 4 5 import java.io.Serializable ; 6 import java.util.Iterator ; 7 import java.util.NoSuchElementException ; 8 9 10 13 public class ArrayIterator implements Iterator , Serializable { 14 15 private Object mArray[]; 16 private int mCurrentElement; 17 private int mArrayLength; 18 private int mOffset; 19 20 public ArrayIterator(Object aobj[]) { 21 mArray = aobj; 22 mCurrentElement = 0; 23 mOffset = 0; 24 mArrayLength = mArray.length; 25 } 26 27 public ArrayIterator(Object aobj[], int i, int j) { 28 mArray = aobj; 29 mCurrentElement = i; 30 mOffset = i; 31 mArrayLength = (j - i) + 1; 32 } 33 34 public boolean hasNext() { 35 return mCurrentElement < mArrayLength + mOffset; 36 } 37 38 public Object next() throws NoSuchElementException { 39 try { 40 mCurrentElement++; 41 return mArray[mCurrentElement - 1]; 42 } catch (ArrayIndexOutOfBoundsException _ex) { 43 throw new NoSuchElementException (); 44 } 45 } 46 47 public void remove() throws UnsupportedOperationException { 48 throw new UnsupportedOperationException (); 49 } 50 } 51 | Popular Tags |