KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > collections > impl > VectorEnumeration


1 package persistence.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/license.html
6  *
7  */

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

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