com.equitysoft.hashstore
Class DuplicateDiskHashtable

java.lang.Object
  |
  +--com.equitysoft.hashstore.DiskHashtable
        |
        +--com.equitysoft.hashstore.DuplicateDiskHashtable
Direct Known Subclasses:
SyncDuplicateDiskHashtable

public class DuplicateDiskHashtable
extends DiskHashtable

This class is an extension of DiskHashTable that allows duplicate (ie. non-unique) keys To retrieve values the programmer should first use get followed by repeated invocations of getNext to retrieve all the duplicate entries for a given key.

Caution should be exercised over how many duplicates of a key are added. The duplicates form a chain and each new duplicate is added to the end of the chain. This class maintains a "current entry" pointer to allow traversing and deletion of entries. After hundreds of duplicates are added, performance may become a problem when adding or deleting since the end of the chain has to be found. Retrieval should never be a problem.

None of the methods are synchronized. The class SyncDuplicateDiskHashtable provides a synchronized version.

Author:
Colin Mummery - equitysoft@iname.com - http://www.kagi.com/equitysoft

Constructor Summary
DuplicateDiskHashtable(java.io.File root)
           
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Gets the object associated with the the first instance of the key.
 java.lang.Object getCurrentKey()
          Returns the current key value or null if none is set.
 java.lang.Object getCurrentValue()
          Returns the value associated with the current key value or null if no current key is set.
 java.lang.Object getNext()
          This method can be repeatedly called after invoking get in order to retrieve all entries in the tabel with the same key.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Puts the specified key and value pair into the table even though the key value may already exist in the table.
 java.lang.Object remove(java.lang.Object key)
          Remove all entries that match the given key.
 java.lang.Object removeCurrent()
          Removes the current entry in the table.
 
Methods inherited from class com.equitysoft.hashstore.DiskHashtable
clear, containsKey, deleteTable, elements, isEmpty, keys, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DuplicateDiskHashtable

public DuplicateDiskHashtable(java.io.File root)
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
                     throws java.io.IOException
Puts the specified key and value pair into the table even though the key value may already exist in the table. The current key value is set to this entry.
Overrides:
put in class DiskHashtable
Returns:
Always returns null. The returned value is necessary for compatability with the super-class.
See Also:
getCurrentKey()

get

public java.lang.Object get(java.lang.Object key)
                     throws java.io.IOException
Gets the object associated with the the first instance of the key. A call to this method should be followed by repeated calls to getNext() to retrieve subsequent values with the same key. If the object causes a ClassNotFoundException when deserializing. , then the exception is transformed into an IOException for convenience.
Overrides:
get in class DiskHashtable
Returns:
null if the key isn't found otherwise the associated object
See Also:
getNext()

getNext

public java.lang.Object getNext()
                         throws java.io.IOException
This method can be repeatedly called after invoking get in order to retrieve all entries in the tabel with the same key.
Returns:
null if the key isn't found otherwise the value associated with the next key entry
See Also:
get(Object)

remove

public java.lang.Object remove(java.lang.Object key)
                        throws java.io.IOException
Remove all entries that match the given key. This method doesn't return a value as more than one entry may be deleted.
Overrides:
remove in class DiskHashtable
Returns:
Always returns null. Returning something is necessary for compatability with the super-class.
See Also:
removeCurrent()

getCurrentKey

public java.lang.Object getCurrentKey()
                               throws java.io.IOException
Returns the current key value or null if none is set. This method is useful if a program needs to check that a current value is set.

getCurrentValue

public java.lang.Object getCurrentValue()
                                 throws java.io.IOException
Returns the value associated with the current key value or null if no current key is set.

removeCurrent

public java.lang.Object removeCurrent()
                               throws java.io.IOException
Removes the current entry in the table. The current entry is set by invoking get followed by repeated calls to getNext to move to the entry to be deleted. After deletion the current entry becomes the following entry with the same key value if there is one.
Returns:
The value associated with the removed entry
See Also:
get(Object), getNext(), remove(Object)