access private members of an inner class inside its innerclass.*/
privateSoftValue(Object k, Object key, ReferenceQueue q){super(k, q);
this.key=key; }
}
/**Here we go through the ReferenceQueue and remove garbagecollected SoftValue objects from the HashMap by looking them
up using the SoftValue.key data member.*/publicvoidprocessQueue(){
SoftValue sv;while((sv=(SoftValue)queue.poll())!=null){
if(sv.get() ==null) { Log.e(" processQueue "," null ");
}else{ Log.e(" processQueue "," Not null ");
} hash.remove(sv.key);//we can access private data!
Log.e(" SoftHashMap "," release" sv.key); }
}/**Here we put the key, value pair into the HashMap using
a SoftValue object.*/publicObject put(Object key, Object value){
processQueue();//throw out garbage collected values first Log.e(" SoftHashMap "," put into" key);
returnhash.put(key,newSoftValue(value, key, queue)); }
publicObject remove(Object key){ processQueue();//throw out garbage collected values first
returnhash.remove(key); }
publicvoidclear(){ hardCache.clear();
processQueue();//throw out garbage collected valueshash.clear();
}publicintsize(){
processQueue();//throw out garbage collected values firstreturnhash.size();
}publicSet entrySet(){
//no, no, you may NOT do that!!! GRRRthrownewUnsupportedOperationException();
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-49607-6.html
我的北京美丽
把侵略者溺死在南海