Methods Summary |
---|
public java.lang.Object | get(java.lang.Object key)Get the value for a key from the Map. The key
will be promoted to the Most Recently Used position.
Note that get(Object) operations will modify
the underlying Collection. Calling get(Object)
inside of an iteration over keys, values, etc. is
currently unsupported.
if(!containsKey(key)) return null;
Object value = remove(key);
super.put(key,value);
return value;
|
public int | getMaximumSize()Getter for property maximumSize.
return maximumSize;
|
protected void | processRemovedLRU(java.lang.Object key, java.lang.Object value)Subclasses of LRUMap may hook into this method to
provide specialized actions whenever an Object is
automatically removed from the cache. By default,
this method does nothing.
|
public java.lang.Object | put(java.lang.Object key, java.lang.Object value)Removes the key and its Object from the Map.
(Note: this may result in the "Least Recently Used"
object being removed from the Map. In that case,
the removeLRU() method is called. See javadoc for
removeLRU() for more details.)
int mapSize = size();
Object retval = null;
if ( mapSize >= maximumSize ) {
// don't retire LRU if you are just
// updating an existing key
if (!containsKey(key)) {
// lets retire the least recently used item in the cache
removeLRU();
}
}
retval = super.put(key,value);
return retval;
|
public void | readExternal(java.io.ObjectInput in)
maximumSize = in.readInt();
int size = in.readInt();
for( int i = 0; i < size; i++ ) {
Object key = in.readObject();
Object value = in.readObject();
put(key,value);
}
|
protected void | removeLRU()This method is used internally by the class for
finding and removing the LRU Object.
Object key = getFirstKey();
// be sure to call super.get(key), or you're likely to
// get infinite promotion recursion
Object value = super.get(key);
remove(key);
processRemovedLRU(key,value);
|
public void | setMaximumSize(int maximumSize)Setter for property maximumSize.
this.maximumSize = maximumSize;
while (size() > maximumSize) {
removeLRU();
}
|
public void | writeExternal(java.io.ObjectOutput out)
out.writeInt( maximumSize );
out.writeInt( size() );
for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) {
Object key = iterator.next();
out.writeObject( key );
// be sure to call super.get(key), or you're likely to
// get infinite promotion recursion
Object value = super.get( key );
out.writeObject( value );
}
|