java.lang.Object | +--org.apache.commons.collections.map.AbstractHashedMapAll Implemented Interfaces:
transient AbstractHashedMap.HashEntry[] | Map entries |
static int | The default capacity to use |
static float | The default load factor to use |
static int | The default threshold to use |
transient AbstractHashedMap.EntrySet | Entry set |
static String | |
static String | |
transient AbstractHashedMap.KeySet | Key set |
transient float | Load factor, normally 0.75 |
static int | The maximum capacity allowed |
transient int | Modification count for iterators |
static String | An abstract implementation of a hash-based map which provides numerous points for subclasses to override. |
static String | |
static Object | An object for masking null |
static String | |
static String | |
transient int | The size of the map |
transient int | Size at which to rehash |
transient AbstractHashedMap.Values | Values |
Constructor only used in deserialization, do not use otherwise. |
AbstractHashedMap(int initialCapacity, float loadFactor, int threshold) Constructor which performs no validation on the passed in parameters. |
AbstractHashedMap(int initialCapacity) Constructs a new, empty map with the specified initial capacity and default load factor. |
AbstractHashedMap(int initialCapacity, float loadFactor) Constructs a new, empty map with the specified initial capacity and load factor. |
AbstractHashedMap(Map map) Constructor copying elements from another map. |
void | addEntry(AbstractHashedMap.HashEntry entry, int hashIndex) Adds an entry into this map. |
void | addMapping(int hashIndex, int hashCode, Object key, Object value) Adds a new key-value mapping into this map. |
int | calculateNewCapacity(int proposedCapacity) Calculates the new capacity of the map. |
int | calculateThreshold(int newCapacity, float factor) Calculates the new threshold of the map, where it will be resized. |
void | Checks the capacity of the map and enlarges it if necessary. |
void | clear() Clears the map, resetting the size to zero and nullifying references to avoid garbage collection issues. |
Object | clone() Clones the map without cloning the keys or values. |
boolean | containsKey(Object key) Checks whether the map contains the specified key. |
boolean | containsValue(Object value) Checks whether the map contains the specified value. |
Object | convertKey(Object key) Converts input keys to another object for storage in the map. |
createEntry(AbstractHashedMap.HashEntry next, int hashCode, Object key, Object value) Creates an entry to store the key-value data. | |
Iterator | Creates an entry set iterator. |
Iterator | Creates a key set iterator. |
Iterator | Creates a values iterator. |
void | destroyEntry(AbstractHashedMap.HashEntry entry) Kills an entry ready for the garbage collector. |
void | doReadObject(ObjectInputStream in) Reads the map data from the stream. |
void | doWriteObject(ObjectOutputStream out) Writes the map data to the stream. |
void | ensureCapacity(int newCapacity) Changes the size of the data structure to the capacity proposed. |
Set | entrySet() Gets the entrySet view of the map. |
boolean | equals(Object obj) Compares this map with another. |
Object | get(Object key) Gets the value mapped to the key specified. |
getEntry(Object key) Gets the entry mapped to the key specified. | |
int | hash(Object key) Gets the hash code for the key specified. |
int | hashCode() Gets the standard Map hashCode. |
int | hashIndex(int hashCode, int dataSize) Gets the index into the data storage for the hashCode specified. |
void | init() Initialise subclasses during construction, cloning or deserialization. |
boolean | isEmpty() Checks whether the map is currently empty. |
boolean | isEqualKey(Object key1, Object key2) Compares two keys for equals. |
boolean | isEqualValue(Object value1, Object value2) Compares two values for equals. |
Set | keySet() Gets the keySet view of the map. |
Gets an iterator over the map. | |
Object | put(Object key, Object value) Puts a key-value mapping into this map. |
void | putAll(Map map) Puts all the values from the specified map into this map. |
Object | remove(Object key) Removes the specified mapping from this map. |
void | removeEntry(AbstractHashedMap.HashEntry entry, int hashIndex, AbstractHashedMap.HashEntry previous) Removes an entry from the chain stored in a particular index. |
void | removeMapping(AbstractHashedMap.HashEntry entry, int hashIndex, AbstractHashedMap.HashEntry previous) Removes a mapping from the map. |
void | reuseEntry(AbstractHashedMap.HashEntry entry, int hashIndex, int hashCode, Object key, Object value) Reuses an existing key-value mapping, storing completely new data. |
int | size() Gets the size of the map. |
String | toString() Gets the map as a String. |
void | updateEntry(AbstractHashedMap.HashEntry entry, Object newValue) Updates an existing key-value mapping to change the value. |
Collection | values() Gets the values view of the map. |
protected transient AbstractHashedMap.HashEntry[] data
protected static final int DEFAULT_CAPACITY
protected static final float DEFAULT_LOAD_FACTOR
protected static final int DEFAULT_THRESHOLD
protected transient AbstractHashedMap.EntrySet entrySet
protected static final String GETKEY_INVALID
protected static final String GETVALUE_INVALID
protected transient AbstractHashedMap.KeySet keySet
protected transient float loadFactor
protected static final int MAXIMUM_CAPACITY
protected transient int modCount
protected static final String NO_NEXT_ENTRY
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.
protected static final String NO_PREVIOUS_ENTRY
protected static final Object NULL
protected static final String REMOVE_INVALID
protected static final String SETVALUE_INVALID
protected transient int size
protected transient int threshold
protected transient AbstractHashedMap.Values values
protected AbstractHashedMap()
protected AbstractHashedMap(int initialCapacity, float loadFactor, int threshold)
protected AbstractHashedMap(int initialCapacity, float loadFactor)
- if the initial capacity is less than one
- if the load factor is less than or equal to zeroprotected AbstractHashedMap(int initialCapacity)
- if the initial capacity is less than oneprotected AbstractHashedMap(Map map)
- if the map is nullprotected void addEntry(AbstractHashedMap.HashEntry entry, int hashIndex)
protected void addMapping(int hashIndex, int hashCode, Object key, Object value)
createEntry()
, addEntry()
and checkCapacity()
.
It also handles changes to modCount
and size
.
Subclasses could override to fully control adds to the map.
protected int calculateNewCapacity(int proposedCapacity)
protected int calculateThreshold(int newCapacity, float factor)
protected void checkCapacity()
public void clear()
protected Object clone()
clone()
, a subclass must implement the
Cloneable
interface and make this method public.
public boolean containsKey(Object key)
public boolean containsValue(Object value)
protected Object convertKey(Object key)
protected AbstractHashedMap.HashEntry createEntry(AbstractHashedMap.HashEntry next, int hashCode, Object key, Object value)
protected Iterator createEntrySetIterator()
protected Iterator createKeySetIterator()
protected Iterator createValuesIterator()
protected void destroyEntry(AbstractHashedMap.HashEntry entry)
protected void doReadObject(ObjectInputStream in)
put()
is used.
Serialization is not one of the JDK's nicest topics. Normal serialization will
initialise the superclass before the subclass. Sometimes however, this isn't
what you want, as in this case the put()
method on read can be
affected by subclass state.
The solution adopted here is to deserialize the state data of this class in
this protected method. This method must be called by the
readObject()
of the first serializable subclass.
Subclasses may override if the subclass has a specific field that must be present
before put()
or calculateThreshold()
will work correctly.
protected void doWriteObject(ObjectOutputStream out)
put()
is used.
Serialization is not one of the JDK's nicest topics. Normal serialization will
initialise the superclass before the subclass. Sometimes however, this isn't
what you want, as in this case the put()
method on read can be
affected by subclass state.
The solution adopted here is to serialize the state data of this class in
this protected method. This method must be called by the
writeObject()
of the first serializable subclass.
Subclasses may override if they have a specific field that must be present
on read before this implementation will work. Generally, the read determines
what must be serialized here, if anything.
protected void ensureCapacity(int newCapacity)
public Set entrySet()
public boolean equals(Object obj)
public Object get(Object key)
protected AbstractHashedMap.HashEntry getEntry(Object key)
protected int hash(Object key)
public int hashCode()
protected int hashIndex(int hashCode, int dataSize)
protected void init()
public boolean isEmpty()
protected boolean isEqualKey(Object key1, Object key2)
protected boolean isEqualValue(Object value1, Object value2)
public Set keySet()
public MapIterator mapIterator()
public Object put(Object key, Object value)
public void putAll(Map map)
- if the map is nullpublic Object remove(Object key)
protected void removeEntry(AbstractHashedMap.HashEntry entry, int hashIndex, AbstractHashedMap.HashEntry previous)
protected void removeMapping(AbstractHashedMap.HashEntry entry, int hashIndex, AbstractHashedMap.HashEntry previous)
removeEntry()
and destroyEntry()
.
It also handles changes to modCount
and size
.
Subclasses could override to fully control removals from the map.
protected void reuseEntry(AbstractHashedMap.HashEntry entry, int hashIndex, int hashCode, Object key, Object value)
public int size()
public String toString()
protected void updateEntry(AbstractHashedMap.HashEntry entry, Object newValue)
setValue()
on the entry.
Subclasses could override to handle changes to the map.
public Collection values()
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.