01: package persistence.antlr.collections.impl;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: import persistence.antlr.collections.List;
10: import persistence.antlr.collections.Stack;
11:
12: import java.util.Enumeration;
13: import java.util.NoSuchElementException;
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 {
22: LLCell cursor;
23: LList list;
24:
25: /**Create an enumeration attached to a LList*/
26: public LLEnumeration(LList l) {
27: list = l;
28: cursor = list.head;
29: }
30:
31: /** Return true/false depending on whether there are more
32: * elements to enumerate.
33: */
34: public boolean hasMoreElements() {
35: if (cursor != null)
36: return true;
37: else
38: return false;
39: }
40:
41: /**Get the next element in the enumeration. Destructive in that
42: * the returned element is removed from the enumeration. This
43: * does not affect the list itself.
44: * @return the next object in the enumeration.
45: */
46: public Object nextElement() {
47: if (!hasMoreElements())
48: throw new NoSuchElementException();
49: LLCell p = cursor;
50: cursor = cursor.next;
51: return p.data;
52: }
53: }
|