|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractMap | +--org.apache.commons.collections.ReferenceMap
Hashtable-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 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
.
Reference
Field Summary | |
static int |
HARD
Constant indicating that hard references should be used. |
static int |
SOFT
Constant indiciating that soft references should be used. |
static int |
WEAK
Constant indicating that weak references should be used. |
Constructor Summary | |
ReferenceMap()
Constructs a new ReferenceMap that will
use hard references to keys and soft references to values. |
|
ReferenceMap(int keyType,
int valueType)
Constructs a new ReferenceMap that will
use the specified types of references. |
|
ReferenceMap(int keyType,
int valueType,
int capacity,
float loadFactor)
Constructs a new ReferenceMap with the
specified reference types, load factor and initial
capacity. |
Method Summary | |
void |
clear()
Clears this map. |
boolean |
containsKey(Object key)
Returns true if this map contains the given key. |
Set |
entrySet()
Returns a set view of this map's entries. |
Object |
get(Object key)
Returns the value associated with the given key, if any. |
boolean |
isEmpty()
Returns true if this map is empty. |
Set |
keySet()
Returns a set view of this map's keys. |
Object |
put(Object key,
Object value)
Associates the given key with the given value. |
Object |
remove(Object key)
Removes the key and its associated value from this map. |
int |
size()
Returns the size of this map. |
Collection |
values()
Returns a collection view of this map's values. |
Methods inherited from class java.util.AbstractMap |
containsValue,
equals,
hashCode,
putAll,
toString |
Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int HARD
public static final int SOFT
public static final int WEAK
Constructor Detail |
public ReferenceMap()
ReferenceMap
that will
use hard references to keys and soft references to values.public ReferenceMap(int keyType, int valueType)
ReferenceMap
that will
use the specified types of references.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
public ReferenceMap(int keyType, int valueType, int capacity, float loadFactor)
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 maploadFactor
- the load factor for the mapMethod Detail |
public int size()
public boolean isEmpty()
true
if this map is empty.true
if this map is emptypublic boolean containsKey(Object key)
true
if this map contains the given key.public Object get(Object key)
null
if the key maps to no valuepublic Object put(Object key, Object value)
Neither the key nor the value may be null.
key
- the key of the mappingvalue
- the value of the mappingpublic Object remove(Object key)
key
- the key to removepublic void clear()
public Set entrySet()
public Set keySet()
public Collection values()
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |