1 16 package org.apache.commons.collections.map; 17 18 import java.io.IOException ; 19 import java.io.ObjectInputStream ; 20 import java.io.ObjectOutputStream ; 21 import java.io.Serializable ; 22 import java.lang.ref.Reference ; 23 24 66 public class ReferenceIdentityMap extends AbstractReferenceMap implements Serializable { 67 68 69 private static final long serialVersionUID = -1266190134568365852L; 70 71 75 public ReferenceIdentityMap() { 76 super(HARD, SOFT, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false); 77 } 78 79 88 public ReferenceIdentityMap(int keyType, int valueType) { 89 super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false); 90 } 91 92 103 public ReferenceIdentityMap(int keyType, int valueType, boolean purgeValues) { 104 super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, purgeValues); 105 } 106 107 118 public ReferenceIdentityMap(int keyType, int valueType, int capacity, float loadFactor) { 119 super(keyType, valueType, capacity, loadFactor, false); 120 } 121 122 135 public ReferenceIdentityMap(int keyType, int valueType, int capacity, 136 float loadFactor, boolean purgeValues) { 137 super(keyType, valueType, capacity, loadFactor, purgeValues); 138 } 139 140 149 protected int hash(Object key) { 150 return System.identityHashCode(key); 151 } 152 153 162 protected int hashEntry(Object key, Object value) { 163 return System.identityHashCode(key) ^ 164 System.identityHashCode(value); 165 } 166 167 177 protected boolean isEqualKey(Object key1, Object key2) { 178 key2 = (keyType > HARD ? ((Reference ) key2).get() : key2); 179 return (key1 == key2); 180 } 181 182 191 protected boolean isEqualValue(Object value1, Object value2) { 192 return (value1 == value2); 193 } 194 195 199 private void writeObject(ObjectOutputStream out) throws IOException { 200 out.defaultWriteObject(); 201 doWriteObject(out); 202 } 203 204 207 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 208 in.defaultReadObject(); 209 doReadObject(in); 210 } 211 212 } 213 | Popular Tags |