/* * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.jmx.remote.util; import java.lang.ref.SoftReference; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.WeakHashMap; import com.sun.jmx.mbeanserver.Util; /** *
Like WeakHashMap, except that the keys of the n most * recently-accessed entries are kept as {@link SoftReference soft * references}. Accessing an element means creating it, or retrieving * it with {@link #get(Object) 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.
*/ public class CacheMapCreate a CacheMap
that can keep up to
* nSoftReferences
as soft references.
nSoftReferences
, so this value
* should not be too great.
*
* @throws IllegalArgumentException if
* nSoftReferences
is negative.
*/
public CacheMap(int nSoftReferences) {
if (nSoftReferences < 0) {
throw new IllegalArgumentException("nSoftReferences = " +
nSoftReferences);
}
this.nSoftReferences = nSoftReferences;
}
public V put(K key, V value) {
cache(key);
return super.put(key, value);
}
public V get(Object key) {
cache(Util.