01: package uk.org.ponder.arrayutil;
02:
03: import java.util.Enumeration;
04:
05: /** This utility class converts a Java array into an Enumeration.
06: */
07:
08: public class ArrayEnumeration implements Enumeration {
09: private Object[] array;
10: private int index;
11: private int limit;
12:
13: /** Constructs an Enumeration from the specified array.
14: * @param array The array to be converted into an enumeration, which may be <code>null</code>
15: */
16:
17: public ArrayEnumeration(Object[] array) {
18: this .array = array;
19: this .index = 0;
20: this .limit = array == null ? 0 : array.length;
21: }
22:
23: /** Constructs an Enumeration from a portion of the supplied array.
24: * @param array The array of which a portion is to be made into an enumeration.
25: * @param index The index of the first array element to be returned from the enumeration.
26: * @param limit One more than the final array element to be returned from the enumeration.
27: */
28:
29: public ArrayEnumeration(Object[] array, int index, int limit) {
30: this .array = array;
31: this .index = index;
32: this .limit = limit;
33: }
34:
35: public boolean hasMoreElements() {
36: return index < limit;
37: }
38:
39: public Object nextElement() {
40: return array[index++];
41: }
42: }
|