Annotation of java/classes/org/w3c/util/ArrayEnumeration.java, revision 1.2
1.1 anto 1: // ArrayEnumeration.java
1.2 ! bmahe 2: // $Id: ArrayEnumeration.java,v 1.1 1996/08/05 18:37:03 anto Exp $
1.1 anto 3: // (c) COPYRIGHT MIT and INRIA, 1996.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
1.2 ! bmahe 6: package org.w3c.util ;
1.1 anto 7:
8: import java.util.* ;
9:
10: /** Iterates through array skipping nulls. */
11: public class ArrayEnumeration implements Enumeration {
12: private int nelems ;
13: private int elemCount ;
14: private int arrayIdx ;
15: private Object[] array ;
16:
17: public ArrayEnumeration(Object[] array) {
18: this(array,array.length) ;
19: }
20:
21: public ArrayEnumeration(Object[] array,int nelems) {
22: arrayIdx = elemCount = 0 ;
23: this.nelems = nelems ;
24: this.array = array ;
25: }
26:
27: public final boolean hasMoreElements() {
28: return elemCount<nelems ;
29: }
30:
31: public final Object nextElement() {
32: while(array[arrayIdx]==null && arrayIdx<array.length)
33: arrayIdx++ ;
34:
35: if(arrayIdx>=array.length)
36: throw new NoSuchElementException() ;
37:
38: elemCount++;
39: return array[arrayIdx++] ;
40: }
41: }
Webmaster