Map implementation that allows mappings to be
removed by the garbage collector and matches keys and values based
on == not equals().
When you construct a ReferenceIdentityMap, 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 default constructor uses hard keys and soft values, providing a memory-sensitive cache.
This map is similar to
ReferenceMap.
It differs in that keys and values in this class are compared using ==.
This map will violate the detail of various Map and map view contracts. As a general rule, don't compare this map to other maps.
This Map implementation does not allow null elements.
Attempting to add a null key or value to the map will raise a NullPointerException.
This implementation is not synchronized.
You can use java. to
provide synchronized access to a ReferenceIdentityMap.
Remember that synchronization will not stop the garbage collector removing entries.
All the available iterators can be reset back to the start by casting to
ResettableIterator and calling reset().
Note that ReferenceIdentityMap is not synchronized and is not thread-safe.
If you wish to use this map from multiple threads concurrently, you must use
appropriate synchronization. The simplest approach is to wrap this map
using java.. This class may throw
exceptions when accessed by concurrent threads without synchronization.
java.lang.ref.Reference
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Serialization version |
| Access | Constructor and Description |
|---|---|
| public | ReferenceIdentityMap()
Constructs a new |
| public | ReferenceIdentityMap(final AbstractReferenceMap.
Constructs a new |
| public | ReferenceIdentityMap(final AbstractReferenceMap.
should the value be automatically purged when the
key is garbage collected purgeValues)Constructs a new |
| public | ReferenceIdentityMap(final AbstractReferenceMap.
the initial capacity for the map capacity, final float the load factor for the map loadFactor)Constructs a new |
| public | ReferenceIdentityMap(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 |
| Modifier and Type | Method and Description |
|---|---|
| protected int | Returns: the hash codethe key to get a hash code for key)Overrides org. |
| protected int | Returns: the hash code, as per the MapEntry specificationthe key to get a hash code for, may be null key, final Object the value to get a hash code for, may be null value)Overrides org. |
| protected boolean | Returns: true if equal by identitythe 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 equal by identitythe first value to compare passed in from outside value1, final Object the second value extracted from the entry via value2)getValue()Overrides org. |
| private void | |
| private void |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version | |
| ReferenceIdentityMap | back to summary |
|---|---|
| public ReferenceIdentityMap() Constructs a new | |
| ReferenceIdentityMap | back to summary |
|---|---|
| public ReferenceIdentityMap(final AbstractReferenceMap. Constructs a new
| |
| ReferenceIdentityMap | back to summary |
|---|---|
| public ReferenceIdentityMap(final AbstractReferenceMap. Constructs a new
| |
| ReferenceIdentityMap | back to summary |
|---|---|
| public ReferenceIdentityMap(final AbstractReferenceMap. Constructs a new
| |
| ReferenceIdentityMap | back to summary |
|---|---|
| public ReferenceIdentityMap(final AbstractReferenceMap. Constructs a new
| |
| hash | back to summary |
|---|---|
| protected int hash(final Object key) Overrides org. Gets the hash code for the key specified. This implementation uses the identity hash code. | |
| hashEntry | back to summary |
|---|---|
| protected int hashEntry(final Object key, final Object value) Overrides org. Gets the hash code for a MapEntry. This implementation uses the identity hash code. | |
| isEqualKey | back to summary |
|---|---|
| protected boolean isEqualKey(final Object key1, Object key2) Overrides org. Compares two keys for equals.
This implementation converts the key from the entry to a real reference
before comparison and uses | |
| isEqualValue | back to summary |
|---|---|
| protected boolean isEqualValue(final Object value1, final Object value2) Overrides org. Compares two values for equals.
This implementation uses | |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Read the map in using a custom routine.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Write the map out using a custom routine.
| |