01: package antlr.collections.impl;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: import antlr.collections.List;
09: import antlr.collections.Stack;
10:
11: import java.util.Enumeration;
12: import java.util.NoSuchElementException;
13:
14: import antlr.collections.impl.LLCell;
15:
16: /**An enumeration of a LList. Maintains a cursor through the list.
17: * bad things would happen if the list changed via another thread
18: * while we were walking this list.
19: */
20: final class LLEnumeration implements Enumeration {
21: LLCell cursor;
22: LList list;
23:
24: /**Create an enumeration attached to a LList*/
25: public LLEnumeration(LList l) {
26: list = l;
27: cursor = list.head;
28: }
29:
30: /** Return true/false depending on whether there are more
31: * elements to enumerate.
32: */
33: public boolean hasMoreElements() {
34: if (cursor != null)
35: return true;
36: else
37: return false;
38: }
39:
40: /**Get the next element in the enumeration. Destructive in that
41: * the returned element is removed from the enumeration. This
42: * does not affect the list itself.
43: * @return the next object in the enumeration.
44: */
45: public Object nextElement() {
46: if (!hasMoreElements())
47: throw new NoSuchElementException();
48: LLCell p = cursor;
49: cursor = cursor.next;
50: return p.data;
51: }
52: }
|