Class Overview
Like WeakHashMap, except that the keys of the n most
recently-accessed entries are kept as soft
references
. Accessing an element means creating it, or retrieving
it with get
. Because these entries are kept
with soft references, they will tend to remain even if their keys
are not referenced elsewhere. But if memory is short, they will
be removed.
Summary
Public Constructors |
|
CacheMap(int nSoftReferences)
Create a CacheMap that can keep up to
nSoftReferences as soft references.
|
Public Methods |
V
|
get(Object key)
Returns the value to which the specified key is mapped,
or null if this map contains no mapping for the key.
|
V
|
put(K key, V value)
Associates the specified value with the specified key in this map.
|
[Expand]
Inherited Methods |
From class
java.util.WeakHashMap
void
|
clear()
Removes all of the mappings from this map.
|
boolean
|
containsKey(Object key)
Returns true if this map contains a mapping for the
specified key.
|
boolean
|
containsValue(Object value)
Returns true if this map maps one or more keys to the
specified value.
|
Set<Entry<K, V>>
|
entrySet()
Returns a Set view of the mappings contained in this map.
|
V
|
get(Object key)
Returns the value to which the specified key is mapped,
or null if this map contains no mapping for the key.
|
boolean
|
isEmpty()
Returns true if this map contains no key-value mappings.
|
Set<K>
|
keySet()
Returns a Set view of the keys contained in this map.
|
V
|
put(K key, V value)
Associates the specified value with the specified key in this map.
|
void
|
putAll(Map<? extends K, ? extends V> m)
Copies all of the mappings from the specified map to this map.
|
V
|
remove(Object key)
Removes the mapping for a key from this weak hash map if it is present.
|
int
|
size()
Returns the number of key-value mappings in this map.
|
Collection<V>
|
values()
Returns a Collection view of the values contained in this map.
|
|
From class
java.util.AbstractMap
void
|
clear()
Removes all of the mappings from this map (optional operation).
This implementation calls entrySet().clear().
|
Object
|
clone()
Returns a shallow copy of this AbstractMap instance: the keys
and values themselves are not cloned.
|
boolean
|
containsKey(Object key)
Returns true if this map contains a mapping for the specified
key.
This implementation iterates over entrySet() searching
for an entry with the specified key.
|
boolean
|
containsValue(Object value)
Returns true if this map maps one or more keys to the
specified value.
This implementation iterates over entrySet() searching
for an entry with the specified value.
|
abstract
Set<Entry<K, V>>
|
entrySet()
Returns a Set view of the mappings contained in this map.
|
boolean
|
equals(Object o)
Compares the specified object with this map for equality.
|
V
|
get(Object key)
Returns the value to which the specified key is mapped,
or null if this map contains no mapping for the key.
This implementation iterates over entrySet() searching
for an entry with the specified key.
|
int
|
hashCode()
Returns the hash code value for this map.
|
boolean
|
isEmpty()
Returns true if this map contains no key-value mappings.
This implementation returns size() == 0.
|
Set<K>
|
keySet()
Returns a Set view of the keys contained in this map.
This implementation returns a set that subclasses AbstractSet .
|
V
|
put(K key, V value)
Associates the specified value with the specified key in this map
(optional operation).
This implementation always throws an
UnsupportedOperationException.
|
void
|
putAll(Map<? extends K, ? extends V> m)
Copies all of the mappings from the specified map to this map
(optional operation).
This implementation iterates over the specified map's
entrySet() collection, and calls this map's put
operation once for each entry returned by the iteration.
|
V
|
remove(Object key)
Removes the mapping for a key from this map if it is present
(optional operation).
This implementation iterates over entrySet() searching for an
entry with the specified key.
|
int
|
size()
Returns the number of key-value mappings in this map.
This implementation returns entrySet().size().
|
String
|
toString()
Returns a string representation of this map.
|
Collection<V>
|
values()
|
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait()
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object.
|
final
void
|
wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
|
final
void
|
wait(long timeout)
Causes the current thread to wait until either another thread invokes the
notify() method or the
notifyAll() method for this object, or a
specified amount of time has elapsed.
|
|
From interface
java.util.Map
abstract
void
|
clear()
Removes all of the mappings from this map (optional operation).
|
abstract
boolean
|
containsKey(Object key)
Returns true if this map contains a mapping for the specified
key.
|
abstract
boolean
|
containsValue(Object value)
Returns true if this map maps one or more keys to the
specified value.
|
abstract
Set<Entry<K, V>>
|
entrySet()
Returns a Set view of the mappings contained in this map.
|
abstract
boolean
|
equals(Object o)
Compares the specified object with this map for equality.
|
abstract
V
|
get(Object key)
Returns the value to which the specified key is mapped,
or null if this map contains no mapping for the key.
|
abstract
int
|
hashCode()
Returns the hash code value for this map.
|
abstract
boolean
|
isEmpty()
Returns true if this map contains no key-value mappings.
|
abstract
Set<K>
|
keySet()
Returns a Set view of the keys contained in this map.
|
abstract
V
|
put(K key, V value)
Associates the specified value with the specified key in this map
(optional operation).
|
abstract
void
|
putAll(Map<? extends K, ? extends V> m)
Copies all of the mappings from the specified map to this map
(optional operation).
|
abstract
V
|
remove(Object key)
Removes the mapping for a key from this map if it is present
(optional operation).
|
abstract
int
|
size()
Returns the number of key-value mappings in this map.
|
abstract
Collection<V>
|
values()
Returns a Collection view of the values contained in this map.
|
|
Public Constructors
public
CacheMap
(int nSoftReferences)
Create a CacheMap
that can keep up to
nSoftReferences
as soft references.
Parameters
nSoftReferences
| Maximum number of keys to keep as soft
references. Access times for get and
put have a component that scales
linearly with nSoftReferences , so this value
should not be too great. |
Public Methods
public
V
get
(Object key)
Returns the value to which the specified key is mapped,
or null
if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key
k
to a value v
such that (key==null ? k==null :
key.equals(k))
, then this method returns v
; otherwise
it returns null
. (There can be at most one such mapping.)
A return value of null
does not necessarily
indicate that the map contains no mapping for the key; it's also
possible that the map explicitly maps the key to null
.
The containsKey
operation may be used to
distinguish these two cases.
Parameters
key
| the key whose associated value is to be returned |
Returns
- the value to which the specified key is mapped, or
null
if this map contains no mapping for the key
public
V
put
(K key, V value)
Associates the specified value with the specified key in this map.
If the map previously contained a mapping for this key, the old
value is replaced.
Parameters
key
| key with which the specified value is to be associated. |
value
| value to be associated with the specified key. |
Returns
- the previous value associated with key, or
null if there was no mapping for key.
(A null return can also indicate that the map
previously associated null with key.)