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.util.Map ; 23 24 37 public class IdentityMap 38 extends AbstractHashedMap implements Serializable , Cloneable { 39 40 41 private static final long serialVersionUID = 2028493495224302329L; 42 43 46 public IdentityMap() { 47 super(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD); 48 } 49 50 56 public IdentityMap(int initialCapacity) { 57 super(initialCapacity); 58 } 59 60 69 public IdentityMap(int initialCapacity, float loadFactor) { 70 super(initialCapacity, loadFactor); 71 } 72 73 79 public IdentityMap(Map map) { 80 super(map); 81 } 82 83 91 protected int hash(Object key) { 92 return System.identityHashCode(key); 93 } 94 95 103 protected boolean isEqualKey(Object key1, Object key2) { 104 return (key1 == key2); 105 } 106 107 115 protected boolean isEqualValue(Object value1, Object value2) { 116 return (value1 == value2); 117 } 118 119 129 protected HashEntry createEntry(HashEntry next, int hashCode, Object key, Object value) { 130 return new IdentityEntry(next, hashCode, key, value); 131 } 132 133 137 protected static class IdentityEntry extends HashEntry { 138 139 protected IdentityEntry(HashEntry next, int hashCode, Object key, Object value) { 140 super(next, hashCode, key, value); 141 } 142 143 public boolean equals(Object obj) { 144 if (obj == this) { 145 return true; 146 } 147 if (obj instanceof Map.Entry == false) { 148 return false; 149 } 150 Map.Entry other = (Map.Entry ) obj; 151 return 152 (getKey() == other.getKey()) && 153 (getValue() == other.getValue()); 154 } 155 156 public int hashCode() { 157 return System.identityHashCode(getKey()) ^ 158 System.identityHashCode(getValue()); 159 } 160 } 161 162 168 public Object clone() { 169 return super.clone(); 170 } 171 172 175 private void writeObject(ObjectOutputStream out) throws IOException { 176 out.defaultWriteObject(); 177 doWriteObject(out); 178 } 179 180 183 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 184 in.defaultReadObject(); 185 doReadObject(in); 186 } 187 188 } 189 | Popular Tags |