一、前言
关于grinder源码包定义net.grinder.util.WeakValueHashMap弱引用自定义Map的实现类,基于java.util.HashMap、java.lang.ref.WeakReference内部实现过程,详情参见源码说明。
二、源码说明
package net.grinder.util;@b@@b@import java.lang.ref.WeakReference;@b@import java.util.HashMap;@b@import java.util.Map;@b@@b@public final class WeakValueHashMap@b@{@b@ private final Map m_map;@b@@b@ public WeakValueHashMap()@b@ {@b@ this.m_map = new HashMap();@b@ }@b@@b@ public void clear()@b@ {@b@ this.m_map.clear();@b@ }@b@@b@ public Object get(Object key)@b@ {@b@ WeakReference reference = (WeakReference)this.m_map.get(key);@b@ return ((reference != null) ? reference.get() : null);@b@ }@b@@b@ public void put(Object key, Object value)@b@ {@b@ this.m_map.put(key, new WeakReference(value));@b@ }@b@@b@ public Object remove(Object key)@b@ {@b@ WeakReference reference = (WeakReference)this.m_map.remove(key);@b@ return ((reference != null) ? reference.get() : null);@b@ }@b@}