|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.util.HashCache
public class HashCache
Creates a hash-keyed cache sensitive to access frequency by combining
a FrequencyModel (for frequency-sorting the
keys) with a Hashtable. Because this is a cache, values are wrapped
in WeakReferences so that there is no strong binding that would deter
garbage collection due to caching.
List) as found in the FrequencyModel class. Most
methods will directly reference the backing Hashtable's keys and
values; only those concerned with ranking will use the
FrequencyModel's keys.
Just as in Hashtable, as a key is removed from the key set(s), the stored Object is removed from the Hashtable's value set. Any access of a key decreases its ranking (i.e., moves it towards the zeroeth position in the list).
This class is almost an opposite of WeakHashMap
since its keys are not weakly linked as in that class, but instead
use WeakReferences as links to its values. Keys never expire in
this class, only what they reference. Since the initial application
for this class was to use Strings (IDs) as keys, a WeakHashMap
wouldn't help much.
This class can also be considered an ordered Map,
since its keys are sorted according to access frequency.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
HashCache()
Constructor for a HashCache. |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all mappings from this Map (optional operation). |
boolean |
contains(Object value)
Returns true if this Map maps one or more keys to the specified value. |
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 |
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. |
Object |
get(Object key)
Returns the value to which this Map maps 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. |
Set |
keySet()
Returns a set view of the keys contained in this Map. |
Object |
put(Object key,
Object value)
Associates the specified value with the specified key in this Map (optional operation). |
void |
putAll(Map t)
Copies all of the mappings from the specified Map to this Map (optional operation). |
int |
rankOf(Object key)
Returns the current ranking of Object key as an int. |
Object |
remove(Object key)
Removes the mapping for this key from this Map if it is present (optional operation). |
void |
setMaximumSize(int max)
If the maximum size is set (by default it is not), the list will be auto-trimmed to limit, from the bottom (least popular). |
int |
size()
Returns the number of key-value mappings in this Map. |
protected void |
trimCache()
Trims the bottom off the cache based on the set limit. |
Collection |
values()
Returns a collection view of the values contained in this map. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public HashCache()
| Method Detail |
|---|
public void clear()
clear in interface MapMap.clear()public boolean containsKey(Object key)
containsKey in interface MapMap.containsKey(Object)public boolean containsValue(Object value)
Note that this method is identical in functionality to
contains(Object) (which predates the Map interface).
containsValue in interface MapMap.containsValue(Object)public Set entrySet()
entrySet in interface MapMap.entrySet()public boolean equals(Object o)
equals in interface Mapequals in class ObjectMap.equals(Object)public Object get(Object key)
FrequencyModel.action(Object),
which decreases (moves towards zero, the "top" of the list) its
ranking.
get in interface MapMap.get(Object)public int hashCode()
hashCode in interface MaphashCode in class ObjectMap.hashCode()public boolean isEmpty()
isEmpty in interface MapMap.isEmpty()public Set keySet()
keySet in interface MapMap.keySet()
public Object put(Object key,
Object value)
put in interface MapMap.put(Object,Object)public void putAll(Map t)
putAll in interface MapMap.putAll(Map)public Object remove(Object key)
remove in interface MapMap.remove(Object)public int size()
size in interface MapMap.size()public Collection values()
values in interface MapMap.values()public boolean contains(Object value)
Note that this method is identical in functionality to
containsValue(Object), (which is part of the Map interface
in the Collections framework).
Map.containsValue(Object)protected void trimCache()
public void setMaximumSize(int max)
public int rankOf(Object key)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||