1: import java.util.Iterator; 2: /** 3: An interface for a dictionary with distinct search keys. 4: @author Frank M. Carrano 5: @author Timothy M. Henry 6: @version 4.0 7: */ 8: public interface DictionaryInterface<K, V> 9: { 10: /** Adds a new entry to this dictionary. If the given search key already 11: exists in the dictionary, replaces the corresponding value. 12: @param key An object search key of the new entry. 13: @param value An object associated with the search key. 14: @return Either null if the new entry was added to the dictionary 15: or the value that was associated with key if that value 16: was replaced. */ 17: public V add(K key, V value); 18: 19: /** Removes a specific entry from this dictionary. 20: @param key An object search key of the entry to be removed. 21: @return Either the value that was associated with the search key 22: or null if no such object exists. */ 23: public V remove(K key); 24: 25: /** Retrieves from this dictionary the value associated with a given 26: search key. 27: @param key An object search key of the entry to be retrieved. 28: @return Either the value that is associated with the search key 29: or null if no such object exists. */ 30: public V getValue(K key); 31: 32: /** Sees whether a specific entry is in this dictionary. 33: @param key An object search key of the desired entry. 34: @return True if key is associated with an entry in the dictionary. */ 35: public boolean contains(K key); 36: 37: /** Creates an iterator that traverses all search keys in this dictionary. 38: @return An iterator that provides sequential access to the search 39: keys in the dictionary. */ 40: public Iterator<K> getKeyIterator(); 41: 42: /** Creates an iterator that traverses all values in this dictionary. 43: @return An iterator that provides sequential access to the values 44: in this dictionary. */ 45: public Iterator<V> getValueIterator(); 46: 47: /** Sees whether this dictionary is empty. 48: @return True if the dictionary is empty. */ 49: public boolean isEmpty(); 50: 51: /** Gets the size of this dictionary. 52: @return The number of entries (key-value pairs) currently 53: in the dictionary. */ 54: public int getSize(); 55: 56: /** Removes all entries from this dictionary. */ 57: public void clear(); 58: } // end DictionaryInterface