This class implements all the features necessary for a subclass hash-based map.
Key-value entries are stored in instances of the HashEntry class,
which can be overridden and replaced. The iterators can similarly be replaced,
without the need to replace the KeySet, EntrySet and Values view classes.
Overridable methods are provided to change the default hashing behaviour, and to change how entries are added to and removed from the map. Hopefully, all you need for unusual subclasses is here.
Note
From Commons Collections 3.1 this class extends AbstractMap. This is to provide backwards compatibility for ReferenceMap between v3.0 and v3.1. This extends clause will be removed in v5.0.
| Modifier and Type | Class and Description |
|---|---|
| protected static class | |
| protected static class | |
| protected static class | |
| protected abstract static class | |
| protected static class | |
| protected static class | |
| protected static class | |
| protected static class | |
| protected static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv transient AbstractHashedMap. | data
Map entries |
| protected static final int | DEFAULT_CAPACITY
The default capacity to use |
| protected static final float | DEFAULT_LOAD_FACTOR
The default load factor to use |
| protected static final int | DEFAULT_THRESHOLD
The default threshold to use |
| pack-priv transient AbstractHashedMap. | entrySet
Entry set |
| protected static final String | |
| protected static final String | |
| pack-priv transient AbstractHashedMap. | keySet
Hides java. |
| pack-priv transient float | loadFactor
Load factor, normally 0.75 |
| protected static final int | MAXIMUM_CAPACITY
The maximum capacity allowed |
| pack-priv transient int | modCount
Modification count for iterators |
| protected static final String | |
| protected static final String | |
| protected static final Object | NULL
An object for masking null |
| protected static final String | |
| protected static final String | |
| pack-priv transient int | size
The size of the map |
| pack-priv transient int | threshold
Size at which to rehash |
| pack-priv transient AbstractHashedMap. | values
Hides java. |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | AbstractHashedMap(final int
the initial capacity, must be a power of two initialCapacity, final float the load factor, must be > 0.0f and generally < 1.0f loadFactor, final int the threshold, must be sensible threshold)Constructor which performs no validation on the passed in parameters. |
| protected | AbstractHashedMap(final int
the initial capacity initialCapacity)Constructs a new, empty map with the specified initial capacity and default load factor. |
| protected | AbstractHashedMap(int
the initial capacity initialCapacity, final float the load factor loadFactor)Constructs a new, empty map with the specified initial capacity and load factor. |
| protected | AbstractHashedMap(final Map<? extends K, ? extends V>
the map to copy map)Constructor copying elements from another map. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| protected void | addEntry(final AbstractHashedMap.
the entry to add entry,the index into the data array to store at hashIndex)Adds an entry into this map. |
| protected void | addMapping(final int
the index into the data array to store at hashIndex, final int the hash code of the key to add hashCode, final K the key to add key, final V the value to add value)Adds a new key-value mapping into this map. |
| protected int | Returns: the normalized new capacitythe proposed capacity proposedCapacity)Calculates the new capacity of the map. |
| protected int | Returns: the new resize thresholdthe new capacity newCapacity, final float the load factor factor)Calculates the new threshold of the map, where it will be resized. |
| protected void | |
| public void | clear()
Overrides java. Implements java. |
| protected AbstractHashedMap | Returns: a shallow cloneOverrides java. |
| public boolean | Returns: true if the map contains the keythe key to search for key)Overrides java. Implements java. |
| public boolean | Returns: true if the map contains the valuethe value to search for value)Overrides java. Implements java. |
| protected Object | Returns: the converted keythe key convert key)Converts input keys to another object for storage in the map. |
| protected AbstractHashedMap. | Returns: the newly created entrythe next entry in sequence next,the hash code to use hashCode, final K the key to store key, final V the value to store value)Creates an entry to store the key-value data. |
| protected Iterator | |
| protected Iterator | |
| protected Iterator | |
| protected void | destroyEntry(final AbstractHashedMap.
the entry to destroy entryKills an entry ready for the garbage collector. |
| protected void | |
| protected void | |
| protected void | ensureCapacity(final int
the new capacity of the array (a power of two, less or equal to max) newCapacity)Changes the size of the data structure to the capacity proposed. |
| protected int | Returns: thehashCode field of the entrythe entry to query, must not be null entryGets the |
| protected K | Returns: thekey field of the entrythe entry to query, must not be null entryGets the |
| protected AbstractHashedMap. | Returns: thenext field of the entrythe entry to query, must not be null entryGets the |
| public Set | Returns: the entrySet viewImplements abstract java. Implements java. |
| protected V | Returns: thevalue field of the entrythe entry to query, must not be null entryGets the |
| public boolean | Returns: true if equalthe object to compare to obj)Overrides java. Implements java. |
| public V | Returns: the mapped value, null if no matchthe key key)Overrides java. Implements java. |
| protected AbstractHashedMap. | |
| protected int | |
| public int | Returns: the hash code defined in the Map interfaceOverrides java. Implements java. |
| protected int | Returns: the bucket indexthe hash code to use hashCode, final int the size of the data to pick a bucket from dataSize)Gets the index into the data storage for the hashCode specified. |
| protected void | |
| public boolean | Returns: true if the map is currently size zeroOverrides java. Implements java. |
| protected boolean | Returns: true if equalthe first key to compare passed in from outside key1, final Object the second key extracted from the entry via key2)entry.keyCompares two keys, in internal converted form, to see if they are equal. |
| protected boolean | Returns: true if equalthe first value to compare passed in from outside value1, final Object the second value extracted from the entry via value2)getValue()Compares two values, in external form, to see if they are equal. |
| public Set | Returns: the keySet viewOverrides java. Implements java. |
| public MapIterator | Returns: the map iteratorImplements org. |
| public V | Returns: the value previously mapped to this key, null if nonethe key to add key, final V the value to add value)Overrides java. Implements java. |
| public void | putAll(final Map<? extends K, ? extends V>
the map to add map)Overrides java. Implements java. |
| public V | Returns: the value mapped to the removed key, null if key not in mapthe mapping to remove key)Overrides java. Implements java. |
| protected void | removeEntry(final AbstractHashedMap.
the entry to remove entry,the index into the data structure hashIndex, final AbstractHashedMap.the previous entry in the chain previousRemoves an entry from the chain stored in a particular index. |
| protected void | removeMapping(final AbstractHashedMap.
the entry to remove entry,the index into the data structure hashIndex, final AbstractHashedMap.the previous entry in the chain previousRemoves a mapping from the map. |
| protected void | reuseEntry(final AbstractHashedMap.
the entry to update, not null entry,the index in the data array hashIndex, final int the hash code of the key to add hashCode, final K the key to add key, final V the value to add value)Reuses an existing key-value mapping, storing completely new data. |
| public int | Returns: the sizeOverrides java. Implements java. |
| public String | Returns: a string version of the mapOverrides java. |
| protected void | updateEntry(final AbstractHashedMap.
the entry to update entry,the new value to store newValue)Updates an existing key-value mapping to change the value. |
| public Collection | Returns: the values viewOverrides java. Implements java. |