-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapADT.java
65 lines (55 loc) · 1.99 KB
/
MapADT.java
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
// --== CS400 Project One File Header ==--
// Name: Riya Kore
// CSL Username: kore
// Email: rykore@wisc.edu
// Lecture #: 003 @2:25pm
// Notes to Grader: <any optional extra notes to your grader>
import java.util.NoSuchElementException;
public interface MapADT <KeyType, ValueType> {
/**
* Inserts a new (key, value) pair into the map if the map does not
* contain a value mapped to key yet.
*
* @param key the key of the (key, value) pair to store
* @param value the value that the key will map to
* @return true if the (key, value) pair was inserted into the map,
* false if a mapping for key already exists and the
* new (key, value) pair could not be inserted
*/
public boolean put(KeyType key, ValueType value);
/**
* Returns the value mapped to a key if the map contains such a mapping.
*
* @param key the key for which to look up the value
* @return the value mapped to the key
* @throws NoSuchElementException if the map does not contain a mapping
* for the key
*/
public ValueType get(KeyType key) throws NoSuchElementException;
/**
* Removes a key and its value from the map.
*
* @param key the key for the (key, value) pair to remove
* @return the value for the (key, value) pair that was removed,
* or null if the map did not contain a mapping for key
*/
public ValueType remove(KeyType key);
/**
* Checks if a key is stored in the map.
*
* @param key the key to check for
* @return true if the key is stored (mapped to a value) by the map
* and false otherwise
*/
public boolean containsKey(KeyType key);
/**
* Returns the number of (key, value) pairs stored in the map.
*
* @return the number of (key, value) pairs stored in the map
*/
public int size();
/**
* Removes all (key, value) pairs from the map.
*/
public void clear();
}