1 package persistence.antlr.collections.impl; 2 3 8 9 import java.util.Hashtable ; 10 import java.util.Enumeration ; 11 12 import persistence.antlr.collections.impl.Vector; 13 14 19 public class IndexedVector { 20 protected Vector elements; 21 protected Hashtable index; 22 23 24 27 public IndexedVector() { 28 elements = new Vector(10); 29 index = new Hashtable (10); 30 } 31 32 36 public IndexedVector(int size) { 37 elements = new Vector(size); 38 index = new Hashtable (size); 39 } 40 41 public synchronized void appendElement(Object key, Object value) { 42 elements.appendElement(value); 43 index.put(key, value); 44 } 45 46 52 public Object elementAt(int i) { 53 return elements.elementAt(i); 54 } 55 56 public Enumeration elements() { 57 return elements.elements(); 58 } 59 60 public Object getElement(Object key) { 61 Object o = index.get(key); 62 return o; 63 } 64 65 66 public synchronized boolean removeElement(Object key) { 67 Object value = index.get(key); 68 if (value == null) { 69 return false; 70 } 71 index.remove(key); 72 elements.removeElement(value); 73 return false; 74 } 75 76 public int size() { 77 return elements.size(); 78 } 79 } 80 | Popular Tags |