|
LimeWire collection component api | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.limewire.collection.FixedsizeHashMap<K,V>
public class FixedsizeHashMap<K,V>
Implements a fixed size HashMap. If FixedsizeHashMap
gets full, no new entry can be inserted into it, except by removing an
entry first. An attempt to add new entry throws a NoMoreStorageException.
try{
FixedsizeHashMap<String, String> fhm = new FixedsizeHashMap<String, String>(3);
fhm.put("myKey1", "Abby");
fhm.put("myKey2", "Bob");
fhm.put("myKey3", "Chris");
System.out.println(fhm);
String ret;
ret = fhm.put("myKey3", "replace");
if(ret != null)
System.out.println("put returned: " + ret);
System.out.println(fhm);
fhm.put("myKey4", "Dan");
} catch (Exception e) {
System.out.println("Exception because of maximum size upon put myKey4 ... " + e.toString() );
}
Output:
{myKey2=Bob, myKey3=Chris, myKey1=Abby}
put returned: Chris
{myKey2=Bob, myKey3=replace, myKey1=Abby}
Exception because of maximum size upon put myKey4 ... org.limewire.collection.NoMoreStorageException
| Constructor Summary | |
|---|---|
FixedsizeHashMap(int size)
Create a new hashMap that stores only the specified number of entries. |
|
| Method Summary | |
|---|---|
void |
clear()
Clears all entries from the map. |
V |
get(K key)
Returns the value mapped to the given key. |
V |
put(K key,
V value)
Maps the given key to the given value. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public FixedsizeHashMap(int size)
size - the number of entries to hold
java.lang.IllegalArgumentException - if size is less < 1.| Method Detail |
|---|
public V put(K key,
V value)
throws NoMoreStorageException
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 notpublic V get(K key)
key - the given key
public void clear()
public java.lang.String toString()
toString in class java.lang.Object
|
LimeWire collection component api | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||