KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > collections > impl > VectorEnumerator


1 package antlr.collections.impl;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/RIGHTS.html
6  *
7  * $Id: //depot/code/org.antlr/main/main/antlr/collections/impl/VectorEnumerator.java#4 $
8  */

9
10 import java.util.Enumeration JavaDoc;
11 import java.util.NoSuchElementException JavaDoc;
12
13 import antlr.collections.Enumerator;
14
15 // based on java.lang.Vector; returns any null indices between non-null ones.
16

17 class VectorEnumerator implements Enumeration JavaDoc {
18     Vector vector;
19     int i;
20
21
22     VectorEnumerator(Vector v) {
23         vector = v;
24         i = 0;
25     }
26
27     public boolean hasMoreElements() {
28         synchronized (vector) {
29             return i <= vector.lastElement;
30         }
31     }
32
33     public Object JavaDoc nextElement() {
34         synchronized (vector) {
35             if (i <= vector.lastElement) {
36                 return vector.data[i++];
37             }
38             throw new NoSuchElementException JavaDoc("VectorEnumerator");
39         }
40     }
41 }
42
Popular Tags