-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryInterface.java
More file actions
82 lines (72 loc) · 2.49 KB
/
DictionaryInterface.java
File metadata and controls
82 lines (72 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.Iterator;
/**
* An interface for a dictionary datatype.
* Search keys are unique in the dictionary.
* Search keys and associated values are not null.
*
* @author Ryan Wei
*/
public interface DictionaryInterface<K, V> {
// interface for dictionary datatype
/**
* Adds a new entry to this dictionary. If the given key already exists in the
* dictionary, replaces the corresponding value.
*
* @param key An object that serves as the key of the new entry.
* @param value An object that is the desired value of the new entry.
* @return Either null if the new entry was added to the dictionary or the value
* that was associated with key if that value was replaced.
*/
public V add(K key, V value);
/**
* Removes a specific entry from this dictionary.
*
* @param key An object that serves as the key of the entry to be removed.
* @return Either the value that was associated with the key or null if no such
* object exists.
*/
public V remove(K key);
/**
* Retrieves the value associated with a given key.
*
* @param key An object that serves as the key of the entry to be retrieved.
* @return Either the value that is associated with the key or null if no such
* object exists.
*/
public V getValue(K key);
/**
* Sees whether a specific entry is in this dictionary.
*
* @param key An object that serves as the key of the desired entry.
* @return True if key is associated with an entry in the dictionary.
*/
public boolean contains(K key);
/**
* Creates an Iterator that traverses all search keys in this dictionary.
*
* @return An Iterator that provides sequential access to the search keys in the dictionary
*/
public Iterator<K> getKeyIterator();
/**
* Creates an Iterator that traverses all values in this dictionary.
*
* @return An Iterator that provides sequential access to the values in this dictionary.
*/
public Iterator<V> getValueIterator();
/**
* Sees whether this dictionary is empty.
*
* @return True if the dictionary is empty.
*/
public boolean isEmpty();
/**
* Gets the size of this dictionary.
*
* @return The number of entries (key-value pairs) currently in the dictionary.
*/
public int getSize();
/**
* Removes all entries from this dictionary.
*/
public void clear();
}