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