com.limegroup.gnutella.util
Class FixedsizeForgetfulHashMap

java.lang.Object
  extended bycom.limegroup.gnutella.util.FixedsizeForgetfulHashMap
All Implemented Interfaces:
java.util.Map

public class FixedsizeForgetfulHashMap
extends java.lang.Object
implements java.util.Map

A stronger version of ForgetfulHashMap. Like ForgetfulHashMap, this is a mapping that "forgets" keys and values using a FIFO replacement policy, much like a cache. Unlike ForgetfulHashMap, it has better-defined replacement policy. Specifically, it allows a key to be remapped to a different value and then "renews" this key so it is the last key to be replaced. All of this is done in constant time.

Restrictions:

Note that some methods of this are unimplemented. Also note that this implements Map but does not extend HashMap, unlike ForgetfulHashMap.


Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
FixedsizeForgetfulHashMap(int size)
          Create a new instance that holds only the last "size" entries.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 java.lang.Object clone()
          Returns a shallow copy of this Map instance: the keys and values themselves are not cloned.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
          Not implemented; behavior undefined
 java.util.Set entrySet()
          Not implemented; behavior undefined
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(java.lang.Object key)
          Returns the value associated with this key.
 int hashCode()
           
 boolean isEmpty()
           
 boolean isFull()
          Tests if the map is full
 java.util.Set keySet()
          Partially implemented. Only keySet().iterator() is well defined.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map.
 void putAll(java.util.Map t)
          Copies all of the mappings from the specified map to this one.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key from this map if present.
 java.lang.Object removeLRUEntry()
          Removes the least recently used entry from the map
 void repOk()
          Tests the invariants described above.
 int size()
           
 java.util.Collection values()
          Not implemented; behavior undefined
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedsizeForgetfulHashMap

public FixedsizeForgetfulHashMap(int size)
Create a new instance that holds only the last "size" entries.

Parameters:
size - the number of entries to hold
Throws:
java.lang.IllegalArgumentException - if size is less < 1.
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Returns the value associated with this key.

Specified by:
get in interface java.util.Map
Returns:
the value associated with this key, or null if no association (possibly because the key was expired)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced. Also if any of the key/value is null, the entry is not inserted.

Specified by:
put in interface java.util.Map
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key, which must not be null
Returns:
previous value associated with specified key, or null if there was no mapping for key..

isFull

public boolean isFull()
Tests if the map is full

Returns:
true, if the map is full (ie if adding any other entry will lead to removal of some other entry to maintain the fixed-size property of the map. Returns false, otherwise

removeLRUEntry

public java.lang.Object removeLRUEntry()
Removes the least recently used entry from the map

Returns:
Value corresponding to the key-value removed from the map

putAll

public void putAll(java.util.Map t)
Copies all of the mappings from the specified map to this one. These mappings replace any mappings that this map had for any of the keys currently in the specified Map. As this is fixed size mapping, some older entries may get removed

Specified by:
putAll in interface java.util.Map
Parameters:
t - Mappings to be stored in this map.

clone

public java.lang.Object clone()
Returns a shallow copy of this Map instance: the keys and values themselves are not cloned.

Returns:
a shallow copy of this map.

remove

public java.lang.Object remove(java.lang.Object key)
Removes the mapping for this key from this map if present.

Specified by:
remove in interface java.util.Map
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

clear

public void clear()
Removes all mappings from this map.

Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

size

public int size()
Specified by:
size in interface java.util.Map

keySet

public java.util.Set keySet()
Partially implemented. Only keySet().iterator() is well defined.

Specified by:
keySet in interface java.util.Map

values

public java.util.Collection values()
Not implemented; behavior undefined

Specified by:
values in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Not implemented; behavior undefined

Specified by:
containsValue in interface java.util.Map

entrySet

public java.util.Set entrySet()
Not implemented; behavior undefined

Specified by:
entrySet in interface java.util.Map

repOk

public void repOk()
Tests the invariants described above.