java.lang.Object | ||
↳ | java.util.AbstractMap<K, V> | |
↳ | org.apache.commons.collections.ReferenceMap |
This class is deprecated.
Moved to map subpackage. Due to be removed in v4.0.
Hash-based Map implementation that allows mappings to be removed by the garbage collector.
When you construct a ReferenceMap
, 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.
The algorithms used are basically the same as those
in java.util.HashMap. In particular, you
can specify a load factor and capacity to suit your
needs. All optional Map
operations are
supported.
However, this Map
implementation does not
allow null elements. Attempting to add a null key or
or a null value to the map will raise a
NullPointerException
.
As usual, this implementation is not synchronized. You
can use synchronizedMap(Map
to
provide synchronized access to a ReferenceMap
.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | HARD | Constant indicating that hard references should be used. | |||||||||
int | SOFT | Constant indicating that soft references should be used. | |||||||||
int | WEAK | Constant indicating that weak references should be used. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
ReferenceMap that will
use hard references to keys and soft references to values. | |||||||||||
Constructs a new
ReferenceMap that will
use the specified types of references. | |||||||||||
Constructs a new
ReferenceMap that will
use the specified types of references. | |||||||||||
Constructs a new
ReferenceMap with the
specified reference types, load factor and initial
capacity. | |||||||||||
Constructs a new
ReferenceMap with the
specified reference types, load factor and initial
capacity. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clears this map.
| |||||||||||
Returns
true if this map contains the given key. | |||||||||||
Returns a set view of this map's entries.
| |||||||||||
Returns the value associated with the given key, if any.
| |||||||||||
Returns
true if this map is empty. | |||||||||||
Returns a set view of this map's keys.
| |||||||||||
Associates the given key with the given value.
| |||||||||||
Removes the key and its associated value from this map.
| |||||||||||
Returns the size of this map.
| |||||||||||
Returns a collection view of this map's values.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.AbstractMap
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
|
Constant indicating that hard references should be used.
Constant indicating that soft references should be used.
Constant indicating that weak references should be used.
Constructs a new ReferenceMap
that will
use hard references to keys and soft references to values.
Constructs a new ReferenceMap
that will
use the specified types of references.
Constructs a new ReferenceMap
with the
specified reference types, load factor and initial
capacity.
keyType | the type of reference to use for keys;
must be HARD , SOFT , WEAK |
---|---|
valueType | the type of reference to use for values;
must be HARD , SOFT , WEAK |
capacity | the initial capacity for the map |
loadFactor | the load factor for the map |
purgeValues | should the value be automatically purged when the key is garbage collected |
Constructs a new ReferenceMap
with the
specified reference types, load factor and initial
capacity.
Clears this map.
Returns true
if this map contains the given key.
Returns a set view of this map's entries.
Returns the value associated with the given key, if any.
null
if the key maps to no value
Returns true
if this map is empty.
true
if this map is empty
Associates the given key with the given value.
Neither the key nor the value may be null.
key | the key of the mapping |
---|---|
value | the value of the mapping |
NullPointerException | if either the key or value is null |
---|
Removes the key and its associated value from this map.
key | the key to remove |
---|
Returns the size of this map.
Returns a collection view of this map's values.