HashMap is an implementation of Map. All optional operations (adding and removing) are supported. Keys and values can be any objects.
| 24 | * removing) are supported. Keys and values can be any objects. |
| 25 | */ |
| 26 | public class HashMap<K, V> extends AbstractMap<K, V> implements Map<K, V>, |
| 27 | Cloneable, Serializable { |
| 28 | |
| 29 | private static final long serialVersionUID = 362498820763181265L; |
| 30 | |
| 31 | /* |
| 32 | * Actual count of entries |
| 33 | */ |
| 34 | transient int elementCount; |
| 35 | |
| 36 | /* |
| 37 | * The internal data structure to hold Entries |
| 38 | */ |
| 39 | transient Entry<K, V>[] elementData; |
| 40 | |
| 41 | /* |
| 42 | * modification count, to keep track of structural modifications between the |
| 43 | * HashMap and the iterator |
| 44 | */ |
| 45 | transient int modCount = 0; |
| 46 | |
| 47 | /* |
| 48 | * default size that an HashMap created using the default constructor would |
| 49 | * have. |
| 50 | */ |
| 51 | private static final int DEFAULT_SIZE = 16; |
| 52 | |
| 53 | /* |
| 54 | * maximum ratio of (stored elements)/(storage size) which does not lead to |
| 55 | * rehash |
| 56 | */ |
| 57 | final float loadFactor; |
| 58 | |
| 59 | /* |
| 60 | * maximum number of elements that can be put in this map before having to |
| 61 | * rehash |
| 62 | */ |
| 63 | int threshold; |
| 64 | |
| 65 | static class Entry<K, V> extends MapEntry<K, V> { |
| 66 | final int origKeyHash; |
| 67 | |
| 68 | Entry<K, V> next; |
| 69 | |
| 70 | Entry(K theKey, int hash) { |
| 71 | super(theKey, null); |
| 72 | this.origKeyHash = hash; |
| 73 | } |
| 74 | |
| 75 | Entry(K theKey, V theValue) { |
| 76 | super(theKey, theValue); |
| 77 | origKeyHash = (theKey == null ? 0 : computeHashCode(theKey)); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | @SuppressWarnings("unchecked") |
| 82 | public Object clone() { |
| 83 | Entry<K, V> entry = (Entry<K, V>) super.clone(); |
nothing calls this directly
no outgoing calls
no test coverage detected