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