1 58 59 62 package org.hibernate.util; 63 64 import java.io.Serializable ; 65 import java.util.Collection ; 66 import java.util.HashMap ; 67 import java.util.Map ; 68 import java.util.Set ; 69 70 87 88 public final class FastHashMap implements Map , Serializable { 89 90 92 95 public FastHashMap() { 96 97 super(); 98 this.map = new HashMap (); 99 100 } 101 102 107 public FastHashMap(int capacity) { 108 109 super(); 110 this.map = new HashMap (capacity); 111 112 } 113 114 120 public FastHashMap(int capacity, float factor) { 121 122 super(); 123 this.map = new HashMap (capacity, factor); 124 125 } 126 127 132 public FastHashMap(Map map) { 133 134 super(); 135 this.map = new HashMap (map); 136 137 } 138 139 141 144 private HashMap map = null; 145 146 148 151 public void clear() { 152 153 synchronized (this) { 154 HashMap temp = (HashMap ) map.clone(); 155 temp.clear(); 156 map = temp; 157 } 158 159 } 160 161 165 public Object clone() { 166 167 return new FastHashMap(map); 168 169 } 170 171 177 public boolean containsKey(Object key) { 178 179 return map.containsKey(key); 180 181 } 182 183 189 public boolean containsValue(Object value) { 190 191 return map.containsValue(value); 192 193 } 194 195 199 public Set entrySet() { 200 201 return map.entrySet(); 202 203 } 204 205 213 public boolean equals(Object o) { 214 215 if (o == this) 217 return true; 218 else if ( !(o instanceof Map ) ) 219 return false; 220 Map mo = (Map ) o; 221 222 224 if ( mo.size() != map.size() ) 225 return false; 226 java.util.Iterator i = map.entrySet().iterator(); 227 while ( i.hasNext() ) { 228 Map.Entry e = (Map.Entry ) i.next(); 229 Object key = e.getKey(); 230 Object value = e.getValue(); 231 if (value == null) { 232 if ( !( mo.get(key) == null && mo.containsKey(key) ) ) 233 return false; 234 } 235 else { 236 if ( !value.equals( mo.get(key) ) ) 237 return false; 238 } 239 } 240 return true; 241 242 } 243 244 252 public Object get(Object key) { 253 254 return map.get(key); 255 256 } 257 258 263 public int hashCode() { 264 265 int h = 0; 266 java.util.Iterator i = map.entrySet().iterator(); 267 while ( i.hasNext() ) 268 h += i.next().hashCode(); 269 return h; 270 271 } 272 273 276 public boolean isEmpty() { 277 278 return map.isEmpty(); 279 280 } 281 282 285 public Set keySet() { 286 287 return map.keySet(); 288 289 } 290 291 299 public Object put(Object key, Object value) { 300 301 synchronized (this) { 302 HashMap temp = (HashMap ) map.clone(); 303 Object result = temp.put(key, value); 304 map = temp; 305 return (result); 306 } 307 308 } 309 310 316 public void putAll(Map in) { 317 318 synchronized (this) { 319 HashMap temp = (HashMap ) map.clone(); 320 temp.putAll(in); 321 map = temp; 322 } 323 324 } 325 326 332 public Object remove(Object key) { 333 334 synchronized (this) { 335 HashMap temp = (HashMap ) map.clone(); 336 Object result = temp.remove(key); 337 map = temp; 338 return (result); 339 } 340 341 } 342 343 346 public int size() { 347 348 return map.size(); 349 350 } 351 352 355 public Collection values() { 356 357 return map.values(); 358 359 } 360 361 public String toString() { return map.toString(); } 362 363 } 364 365 366 367 368 369 | Popular Tags |