public class

CacheMap

extends WeakHashMap<K, V>
java.lang.Object
   ↳ java.util.AbstractMap<K, V>
     ↳ java.util.WeakHashMap<K, V>
       ↳ com.sun.jmx.remote.util.CacheMap<K, V>

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
From class java.util.AbstractMap
From class java.lang.Object
From interface java.util.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.
Throws
IllegalArgumentException if nSoftReferences is negative.

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.)