DataStructures
Interface LookupTable

All Known Implementing Classes:
ProbingHashTable

public interface LookupTable

A simple interface for a lookup table. Enables objects to be stored and retrieved using keys. Any object can be used as a key and any object can be used as the corresponding value.

Author:
Peter Williams

Inner Class Summary
static interface LookupTable.Entry
          A class of objects returned by iteration over entries.
 
Method Summary
 void add(java.lang.Object key, java.lang.Object value)
          Adds the specified entry to the table.
 boolean contains(java.lang.Object key)
          Returns true if the table contains an entry for this key.
 boolean isEmpty()
          Tests if the table is empty.
 java.util.Iterator iterator()
          Iterates over the table's entries.
 java.lang.Object lookup(java.lang.Object key)
          Returns the value associated with the specified key.
 void remove(java.lang.Object key)
          Removes the entry corresponding to the key.
 int size()
          Returns the number of entries in the table.
 

Method Detail

isEmpty

public boolean isEmpty()
Tests if the table is empty.
Returns:
the status of the table

size

public int size()
Returns the number of entries in the table.
Returns:
the number of entries.

contains

public boolean contains(java.lang.Object key)
Returns true if the table contains an entry for this key.
Parameters:
key - the key to be searched for
Returns:
true if the table contains an entry for this key

add

public void add(java.lang.Object key,
                java.lang.Object value)
Adds the specified entry to the table. If the key is already present, its value is overwritten.
Parameters:
key - the key of the entry
value - the value of the entry

remove

public void remove(java.lang.Object key)
Removes the entry corresponding to the key. Does nothing if the key is not present.
Parameters:
key - the key of the entry to be removed

lookup

public java.lang.Object lookup(java.lang.Object key)
Returns the value associated with the specified key.
Parameters:
key - the key to be searched for
Returns:
the value for the key
Throws:
NoSuchElementException - if key is not present

iterator

public java.util.Iterator iterator()
Iterates over the table's entries. The next method of the iterator returns a (key, value) pair in the form of a LookupTable.Entry
Returns:
the iterator
See Also:
LookupTable.Entry