-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapADT.java
More file actions
61 lines (52 loc) · 1.94 KB
/
MapADT.java
File metadata and controls
61 lines (52 loc) · 1.94 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
import java.util.NoSuchElementException;
/**
* This abstract data type represents a collection that maps keys to values,
* in which duplicate keys are not allowed (each key maps to exactly one value).
*/
public interface MapADT<KeyType, ValueType> {
/**
* Adds a new key,value pair/mapping to this collection.
* @param key the key of the key,value pair
* @param value the value that key maps to
* @throws IllegalArgumentException if key already maps to a value
* @throws NullPointerException if key is null
*/
public void put(KeyType key, ValueType value) throws IllegalArgumentException;
/**
* Checks whether a key maps to a value in this collection.
* @param key the key to check
* @return true if the key maps to a value, and false is the
* key doesn't map to a value
*/
public boolean containsKey(KeyType key);
/**
* Retrieves the specific value that a key maps to.
* @param key the key to look up
* @return the value that key maps to
* @throws NoSuchElementException when key is not stored in this
* collection
*/
public ValueType get(KeyType key) throws NoSuchElementException;
/**
* Remove the mapping for a key from this collection.
* @param key the key whose mapping to remove
* @return the value that the removed key mapped to
* @throws NoSuchElementException when key is not stored in this
* collection
*/
public ValueType remove(KeyType key) throws NoSuchElementException;
/**
* Removes all key,value pairs from this collection.
*/
public void clear();
/**
* Retrieves the number of keys stored in this collection.
* @return the number of keys stored in this collection
*/
public int getSize();
/**
* Retrieves this collection's capacity.
* @return the size of te underlying array for this collection
*/
public int getCapacity();
}