com.larvalabs.megamap
Class MegaMap

java.lang.Object
  extended bycom.larvalabs.megamap.MegaMap
All Implemented Interfaces:
java.lang.Runnable

public class MegaMap
extends java.lang.Object
implements java.lang.Runnable

An efficient, unbounded map (hashtable) that can optionally persist between VM invocations. Keys are stored in memory, but values may be extremely large. They will be persisted to disk as required by the garbage collector of the VM.

Author:
John Watkinson

Method Summary
 java.io.Serializable get(java.io.Serializable key)
          Gets the value for the given key.
 java.util.Set getKeys()
          Gets all the keys stored in the MegaMap.
 boolean hasKey(java.io.Serializable key)
          Checks if there is a value stored in the MegaMap for the given key.
 void put(java.io.Serializable key, java.io.Serializable value)
          Put a value in the MegaMap.
 void remove(java.io.Serializable key)
          Removes the value for the given key.
 void run()
          Called by the thread that managed the MegaMap disk persistence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

put

public void put(java.io.Serializable key,
                java.io.Serializable value)
Put a value in the MegaMap. Both the key and value must be Serializable objects. If there is already a value stored for this key, it will be over-written.


get

public java.io.Serializable get(java.io.Serializable key)
                         throws MegaMapException
Gets the value for the given key.

Parameters:
key -
Throws:
MegaMapException
See Also:
hasKey(java.io.Serializable)

remove

public void remove(java.io.Serializable key)
Removes the value for the given key.

Parameters:
key -

hasKey

public boolean hasKey(java.io.Serializable key)
Checks if there is a value stored in the MegaMap for the given key. This method should be used to check for the existence of keys instead of get(java.io.Serializable) as it could be far more efficient than get(java.io.Serializable). This is becauseget may have to load the object from disk.

Parameters:
key - the key to search for.
Returns:
true if there is a value stored for the given key, false otherwise.

getKeys

public java.util.Set getKeys()
Gets all the keys stored in the MegaMap.

Returns:
a set of all Keys. This set is not "live", it may be modified without fear of damaging the MegaMap.

run

public void run()
Called by the thread that managed the MegaMap disk persistence. Do not use directly.

Specified by:
run in interface java.lang.Runnable