KickJava   Java API By Example, From Geeks To Geeks.

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


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/LLEnumeration.java#4 $
8  */

9
10 import antlr.collections.List;
11 import antlr.collections.Stack;
12
13 import java.util.Enumeration JavaDoc;
14 import java.util.NoSuchElementException JavaDoc;
15
16 import antlr.collections.impl.LLCell;
17
18 /**An enumeration of a LList. Maintains a cursor through the list.
19  * bad things would happen if the list changed via another thread
20  * while we were walking this list.
21  */

22 final class LLEnumeration implements Enumeration JavaDoc {
23     LLCell cursor;
24     LList list;
25
26
27     /**Create an enumeration attached to a LList*/
28     public LLEnumeration(LList l) {
29         list = l;
30         cursor = list.head;
31     }
32
33     /** Return true/false depending on whether there are more
34      * elements to enumerate.
35      */

36     public boolean hasMoreElements() {
37         if (cursor != null)
38             return true;
39         else
40             return false;
41     }
42
43     /**Get the next element in the enumeration. Destructive in that
44      * the returned element is removed from the enumeration. This
45      * does not affect the list itself.
46      * @return the next object in the enumeration.
47      */

48     public Object JavaDoc nextElement() {
49         if (!hasMoreElements()) throw new NoSuchElementException JavaDoc();
50         LLCell p = cursor;
51         cursor = cursor.next;
52         return p.data;
53     }
54 }
55
Popular Tags