1 package org.jacorb.util; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 import java.util.Set ; 6 7 18 public class IdentityHashMap extends HashMap 19 { 20 public Object put(Object key, Object value) 21 { 22 return super.put(new IdentityWrapper(key), value); 23 } 24 25 public Object get(Object key) 26 { 27 return super.get(new IdentityWrapper(key)); 28 } 29 30 public Object remove(Object key) 31 { 32 return super.remove(new IdentityWrapper(key)); 33 } 34 35 public boolean containsKey(Object key) 36 { 37 return super.containsKey(new IdentityWrapper(key)); 38 } 39 40 public boolean containsValue(Object value) 41 { 42 throw new RuntimeException ("containsValue() not implemented"); 43 } 44 45 public Set entrySet() 46 { 47 throw new RuntimeException ("entrySet() not implemented"); 48 } 49 50 public Set keySet() 51 { 52 throw new RuntimeException ("keySet() not implemented"); 53 } 54 55 public void putAll(Map m) 56 { 57 throw new RuntimeException ("putAll() not implemented"); 58 } 59 60 64 private static class IdentityWrapper 65 { 66 private Object value; 67 68 public IdentityWrapper(Object value) 69 { 70 this.value = value; 71 } 72 73 public boolean equals(Object other) 74 { 75 if (other instanceof IdentityWrapper) 76 return this.value == ((IdentityWrapper)other).value; 77 else 78 return false; 79 } 80 81 public int hashCode() 82 { 83 return value.hashCode(); 84 } 85 } 86 87 } 88 | Popular Tags |