1	package antlr.collections.impl;
2	
3	/** A Linked List Implementation (not thread-safe for simplicity) */
4	import antlr.collections.List;
5	import antlr.collections.Stack;
6	import java.util.Enumeration;
7	import java.util.NoSuchElementException;
8	import antlr.collections.impl.LLCell;
9	
10	/**An enumeration of a LList.  Maintains a cursor through the list.
11	 * bad things would happen if the list changed via another thread
12	 * while we were walking this list.
13	 */
14	final class LLEnumeration implements Enumeration {
15		LLCell cursor;
16		LList list;
17	
18	
19		/**Create an enumeration attached to a LList*/
20		public LLEnumeration(LList l) {list = l; cursor=list.head;}
21		/** Return true/false depending on whether there are more
22		 * elements to enumerate.
23		 */
24		public boolean hasMoreElements() {
25			if ( cursor!=null ) return true;
26			else return false;
27		}
28		/**Get the next element in the enumeration.  Destructive in that
29		 * the returned element is removed from the enumeration.  This
30		 * does not affect the list itself.
31		 * @return the next object in the enumeration.
32		 */
33		public Object nextElement() {
34			if ( !hasMoreElements() ) throw new NoSuchElementException();
35			LLCell p = cursor;
36			cursor = cursor.next;
37			return p.data;
38		}
39	}
40