KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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