public class ReferenceMap extends AbstractMap
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 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 Collections.synchronizedMap(java.util.Map) to
provide synchronized access to a ReferenceMap.
ReferenceAbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry| Modifier and Type | Field and Description |
|---|---|
static int |
HARD
Deprecated.
Constant indicating that hard references should be used.
|
static int |
SOFT
Deprecated.
Constant indicating that soft references should be used.
|
static int |
WEAK
Deprecated.
Constant indicating that weak references should be used.
|
| Constructor and Description |
|---|
ReferenceMap()
Deprecated.
Constructs a new
ReferenceMap that will
use hard references to keys and soft references to values. |
ReferenceMap(int keyType,
int valueType)
Deprecated.
Constructs a new
ReferenceMap that will
use the specified types of references. |
ReferenceMap(int keyType,
int valueType,
boolean purgeValues)
Deprecated.
Constructs a new
ReferenceMap that will
use the specified types of references. |
ReferenceMap(int keyType,
int valueType,
int capacity,
float loadFactor)
Deprecated.
Constructs a new
ReferenceMap with the
specified reference types, load factor and initial
capacity. |
ReferenceMap(int keyType,
int valueType,
int capacity,
float loadFactor,
boolean purgeValues)
Deprecated.
Constructs a new
ReferenceMap with the
specified reference types, load factor and initial
capacity. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Deprecated.
Clears this map.
|
boolean |
containsKey(Object key)
Deprecated.
Returns
true if this map contains the given key. |
Set |
entrySet()
Deprecated.
Returns a set view of this map's entries.
|
Object |
get(Object key)
Deprecated.
Returns the value associated with the given key, if any.
|
boolean |
isEmpty()
Deprecated.
Returns
true if this map is empty. |
Set |
keySet()
Deprecated.
Returns a set view of this map's keys.
|
Object |
put(Object key,
Object value)
Deprecated.
Associates the given key with the given value.
|
Object |
remove(Object key)
Deprecated.
Removes the key and its associated value from this map.
|
int |
size()
Deprecated.
Returns the size of this map.
|
Collection |
values()
Deprecated.
Returns a collection view of this map's values.
|
clone, containsValue, equals, hashCode, putAll, toStringpublic static final int HARD
public static final int SOFT
public static final int WEAK
public ReferenceMap()
ReferenceMap that will
use hard references to keys and soft references to values.public ReferenceMap(int keyType,
int valueType,
boolean purgeValues)
ReferenceMap that will
use the specified types of references.public ReferenceMap(int keyType,
int valueType)
ReferenceMap that will
use the specified types of references.public ReferenceMap(int keyType,
int valueType,
int capacity,
float loadFactor,
boolean purgeValues)
ReferenceMap with the
specified reference types, load factor and initial
capacity.keyType - the type of reference to use for keys;
must be HARD, SOFT, WEAKvalueType - the type of reference to use for values;
must be HARD, SOFT, WEAKcapacity - the initial capacity for the maploadFactor - the load factor for the mappurgeValues - should the value be automatically purged when the
key is garbage collectedpublic ReferenceMap(int keyType,
int valueType,
int capacity,
float loadFactor)
ReferenceMap with the
specified reference types, load factor and initial
capacity.public int size()
size in interface Mapsize in class AbstractMappublic boolean isEmpty()
true if this map is empty.isEmpty in interface MapisEmpty in class AbstractMaptrue if this map is emptypublic boolean containsKey(Object key)
true if this map contains the given key.containsKey in interface MapcontainsKey in class AbstractMappublic Object get(Object key)
get in interface Mapget in class AbstractMapnull
if the key maps to no valuepublic Object put(Object key, Object value)
Neither the key nor the value may be null.
put in interface Mapput in class AbstractMapkey - the key of the mappingvalue - the value of the mappingNullPointerException - if either the key or value
is nullpublic Object remove(Object key)
remove in interface Mapremove in class AbstractMapkey - the key to removepublic void clear()
clear in interface Mapclear in class AbstractMappublic Set entrySet()
entrySet in interface MapentrySet in class AbstractMappublic Set keySet()
keySet in interface MapkeySet in class AbstractMappublic Collection values()
values in interface Mapvalues in class AbstractMapCopyright © 2001–2015 The Apache Software Foundation. All rights reserved.