com.limegroup.gnutella.util
Class FixedsizeHashMap

java.lang.Object
  extended bycom.limegroup.gnutella.util.FixedsizeHashMap

public class FixedsizeHashMap
extends java.lang.Object

This class implements fixed size HashMap. If its get full, no new entry can be inserted into it, except by removing some entry first. An attempt to add new entry throws an NoMoreStorageException

See Also:
NoMoreStorageException

Constructor Summary
FixedsizeHashMap(int size)
          Create a new hashMap that stores only the specified number of entries
 
Method Summary
 java.util.Set entrySet()
          Returns the Set that contains all the entries in the Map
 java.lang.Object get(java.lang.Object key)
          Returns the value mapped to the given key
 boolean isFull()
          checks if the hash Map is full or not (ie if for adding new item we need to remove some item This method is not synchronized (it doesnt matter much if the count is 1 off or so)
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Maps the given key to the given value.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping specified by given key from the underlying datastructure
 java.lang.String toString()
          Returns the string representation of the mappings
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FixedsizeHashMap

public FixedsizeHashMap(int size)
Create a new hashMap that stores only the specified number of entries

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

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
                     throws NoMoreStorageException
Maps the given key to the given value. If adding the key would make this contain more elements than the size given at construction, the passed entry is not stored and NoMoreStorageException gets throwned.

Throws:
NoMoreStorageException - when no more space left in the storage ideally, before calling put method, it should be checked whether the map is already full or not
See Also:
isfull()

get

public java.lang.Object get(java.lang.Object key)
Returns the value mapped to the given key

Parameters:
key - The given key
Returns:
the value given key maps to

remove

public java.lang.Object remove(java.lang.Object key)
Removes the mapping specified by given key from the underlying datastructure

Parameters:
key - The key to be removed
Returns:
the value associated with the key, or null if the key was not present

entrySet

public java.util.Set entrySet()
Returns the Set that contains all the entries in the Map

Returns:
the Set that contains all the entries in the Map

isFull

public boolean isFull()
checks if the hash Map is full or not (ie if for adding new item we need to remove some item This method is not synchronized (it doesnt matter much if the count is 1 off or so)

Returns:
true if the map is full, false otherwise

toString

public java.lang.String toString()
Returns the string representation of the mappings

Returns:
the string representation of the mappings