1 package org.apache.ojb.broker.util; 2 3 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 27 public final class IdentityHashMap extends HashMap 28 { 29 private static final class IdentityKey 30 { 31 private final Object m_key; 32 33 public IdentityKey(final Object key) 34 { 35 m_key = key; 36 } 37 38 public boolean equals(final Object o) 39 { 40 return (o == m_key); 41 } 42 43 public int hashCode() 44 { 45 return System.identityHashCode(m_key); 46 } 47 } 48 49 54 public IdentityHashMap(final int initialCapacity, final float loadFactor) 55 { 56 super(initialCapacity, loadFactor); 57 } 58 59 63 public IdentityHashMap(final int initialCapacity) 64 { 65 super(initialCapacity); 66 } 67 68 71 public IdentityHashMap() 72 { 73 super(); 74 } 75 76 80 public IdentityHashMap(final Map t) 81 { 82 super(t); 83 } 84 85 88 public Object get(final Object key) 89 { 90 return super.get(new IdentityKey(key)); 91 } 92 93 96 public Object put(final Object key, final Object value) 97 { 98 return super.put(new IdentityKey(key), value); 99 } 100 101 104 public Object add(final Object value) 105 { 106 final Object key = new IdentityKey(value); 107 if (!super.containsKey(key)) 108 { 109 return super.put(key, value); 110 } 111 else 112 { 113 return null; 114 } 115 } 116 117 120 public Object remove(final Object key) 121 { 122 return super.remove(new IdentityKey(key)); 123 } 124 125 128 public boolean containsKey(final Object key) 129 { 130 return super.containsKey(new IdentityKey(key)); 131 } 132 } 133 134 | Popular Tags |