1	package antlr.collections.impl;
2	
3	/**
4	 * A simple indexed vector: a normal vector except that you must
5	 * specify a key when adding an element.  This allows fast lookup
6	 * and allows the order of specification to be preserved. 
7	 */
8	import java.util.Hashtable;
9	import java.util.Enumeration;
10	import antlr.collections.impl.Vector;
11	
12	public class IndexedVector {
13		protected Vector elements;
14		protected Hashtable index;
15	
16	
17	/**
18	 * IndexedVector constructor comment.
19	 */
20	public IndexedVector() {
21		elements = new Vector(10);
22		index = new Hashtable(10);
23	}
24	/**
25	 * IndexedVector constructor comment.
26	 * @param size int
27	 */
28	public IndexedVector(int size) {
29		elements = new Vector(size);
30		index = new Hashtable(size);
31	}
32		public synchronized void appendElement(Object key, Object value) {
33			elements.appendElement(value);
34			index.put(key, value);
35		}
36		/**
37		 * Returns the element at the specified index.
38		 * @param index the index of the desired element
39		 * @exception ArrayIndexOutOfBoundsException If an invalid
40		 * index was given.
41		 */
42		public Object elementAt(int i) {
43			return elements.elementAt(i);
44		}
45		public Enumeration elements() {
46			return elements.elements();
47		}
48		public Object getElement(Object key) {
49			Object o = index.get(key);
50			return o;
51		}
52		/** remove element referred to by key NOT value; return false if not found. */
53		public synchronized boolean removeElement(Object key) {
54			Object value = index.get(key);
55			if ( value == null ) {
56				return false;
57			}
58			index.remove(key);
59			elements.removeElement(value);
60			return false;
61		}
62		public int size() {
63			return elements.size();
64		}
65	}
66