This class implements all the features necessary for a subclass reference
hash-based map. Key-value entries are stored in instances of the
ReferenceEntry 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.
When you construct an AbstractReferenceMap, you can specify what
kind of references are used to store the map's keys and values.
If non-hard references are used, then the garbage collector can remove
mappings if a key or value becomes unreachable, or if the JVM's memory is
running low. For information on how the different reference types behave,
see Reference.
Different types of references can be specified for keys and values.
The keys can be configured to be weak but the values hard,
in which case this class will behave like a
WeakHashMap. However, you can also specify hard keys and
weak values, or any other combination. The default constructor uses
hard keys and soft values, providing a memory-sensitive cache.
This Map implementation does not allow null elements.
Attempting to add a null key or value to the map will raise a
NullPointerException.
All the available iterators can be reset back to the start by casting to
ResettableIterator and calling reset().
This implementation is not synchronized.
You can use java. to
provide synchronized access to a ReferenceMap.
java.lang.ref.Reference
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| protected static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| public static enum | AbstractReferenceMap.ReferenceStrength
Reference type enum. |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private AbstractReferenceMap. | keyType
The reference type for keys. |
| private boolean | purgeValues
Should the value be automatically purged when the associated key has been collected? |
| private transient ReferenceQueue | queue
ReferenceQueue used to eliminate stale mappings. |
| private AbstractReferenceMap. | valueType
The reference type for values. |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | AbstractReferenceMap(final AbstractReferenceMap.
the initial capacity for the map capacity, final float the load factor for the map loadFactor, final boolean should the value be automatically purged when the
key is garbage collected purgeValues)Constructs a new empty map with the specified reference types, load factor and initial capacity. |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Overrides org. Implements java. |
| public boolean | Returns: true if the map contains the keythe key to search for key)Overrides org. Implements java. |
| public boolean | Returns: true if the map contains the valuethe value to search for value)Overrides org. Implements java. |
| protected AbstractReferenceMap. | 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)Overrides org. |
| protected Iterator | Returns: the entrySet iteratorOverrides org. |
| protected Iterator | Returns: the keySet iteratorOverrides org. |
| protected Iterator | Returns: the values iteratorOverrides org. |
| protected void | doReadObject(final ObjectInputStream
the input stream in)Overrides org. |
| protected void | doWriteObject(final ObjectOutputStream
the output stream out)Overrides org. |
| public Set | Returns: a set view of this map's entriesOverrides org. Implements java. |
| public V | Returns: the mapped value, null if no matchthe key key)Overrides org. Implements java. |
| protected AbstractHashedMap. | Returns: the entry, null if no matchthe key key)Overrides org. |
| protected int | |
| protected void | init()
Overrides org. |
| public boolean | Returns: true if the map is currently size zeroOverrides org. Implements java. |
| protected boolean | Returns: true if equalthe first key to compare passed in from outside key1, Object the second key extracted from the entry via key2)entry.keyOverrides org. |
| protected boolean | Returns: true if keyType has the specified typethe type to check against. typeProvided protected read-only access to the key type. |
| protected boolean | Returns: true if valueType has the specified typethe type to check against. typeProvided protected read-only access to the value type. |
| public Set | Returns: a set view of this map's keysOverrides org. Implements java. |
| public MapIterator | Returns: a map iteratorOverrides org. Implements org. |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| public V | Returns: the value previously mapped to this key, null if nonethe key to add, must not be null key, final V the value to add, must not be null value)Overrides org. Implements java. |
| public V | Returns: the value mapped to the removed key, null if key not in mapthe mapping to remove key)Overrides org. Implements java. |
| public int | Returns: the sizeOverrides org. Implements java. |
| public Collection | Returns: a set view of this map's valuesOverrides org. Implements java. |