1 58 59 package org.apache.ecs.storage; 60 61 import java.util.Enumeration ; 62 import java.util.Vector ; 63 64 public class Hash implements java.io.Serializable 65 { 66 private Array keys = new Array(); 67 private Array elements = new Array(); 68 69 public Hash() 70 { 71 } 72 73 public void setSize(int newSize) 74 { 75 keys.setSize(newSize); 76 elements.setSize(newSize); 77 } 78 79 public void setGrow(int growBy) 80 { 81 keys.setGrow(growBy); 82 elements.setGrow(growBy); 83 } 84 85 public synchronized void put(String key,Object element) 86 { 87 try 88 { 89 if( containsKey(key) ) 90 { 91 elements.add(keys.location(key),element); 92 } 93 else 94 { 95 keys.add( key ); 96 elements.add(element); 97 } 98 } 99 catch(org.apache.ecs.storage.NoSuchObjectException nsoe) 100 { 101 } 102 } 103 104 public synchronized void remove(String key) 105 { 106 try 107 { 108 if(containsKey(key)) 109 { 110 elements.remove(keys.location(key)); 111 elements.remove(elements.location(key)); 112 } 113 } 114 catch(org.apache.ecs.storage.NoSuchObjectException nsoe) 115 { 116 } 117 } 118 119 public int size() 120 { 121 return keys.getCurrentSize(); 122 } 123 124 public boolean contains(Object element) 125 { 126 try 127 { 128 elements.location(element); 129 return(true); 130 } 131 catch(org.apache.ecs.storage.NoSuchObjectException noSuchObject) 132 { 133 return false; 134 } 135 } 136 137 public Enumeration keys() 138 { 139 return keys; 140 } 141 142 public boolean containsKey(String key) 143 { 144 try 145 { 146 keys.location(key); 147 } 148 catch(org.apache.ecs.storage.NoSuchObjectException noSuchObject) 149 { 150 return false; 151 } 152 return(true); 153 } 154 155 public Enumeration elements() 156 { 157 return elements; 158 } 159 160 public Object get(String key) 161 { 162 try 163 { 164 if( containsKey(key) ) 165 return(elements.get(keys.location(key))); 166 } 167 catch(org.apache.ecs.storage.NoSuchObjectException nsoe) 168 { 169 } 170 return null; 171 } 172 } 173 | Popular Tags |