01: // ArrayEnumeration.java
02: // $Id: ArrayEnumeration.java,v 1.3 2000/08/16 21:37:57 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.util;
07:
08: import java.util.Enumeration;
09: import java.util.NoSuchElementException;
10:
11: /** Iterates through array skipping nulls. */
12: public class ArrayEnumeration implements Enumeration {
13: private int nelems;
14: private int elemCount;
15: private int arrayIdx;
16: private Object[] array;
17:
18: public ArrayEnumeration(Object[] array) {
19: this (array, array.length);
20: }
21:
22: public ArrayEnumeration(Object[] array, int nelems) {
23: arrayIdx = elemCount = 0;
24: this .nelems = nelems;
25: this .array = array;
26: }
27:
28: public final boolean hasMoreElements() {
29: return elemCount < nelems;
30: }
31:
32: public final Object nextElement() {
33: while (array[arrayIdx] == null && arrayIdx < array.length)
34: arrayIdx++;
35:
36: if (arrayIdx >= array.length)
37: throw new NoSuchElementException();
38:
39: elemCount++;
40: return array[arrayIdx++];
41: }
42: }
|