This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map.java
109 lines (97 loc) · 2.36 KB
/
Map.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package assign09;
import java.util.List;
/**
* This interface represents a map of keys to values. It cannot contain
* duplicate keys, and each key can map to at most one value.
*
* @author Erin Parker
* @version March 24, 2021
*
* @param <K> - placeholder for key type
* @param <V> - placeholder for value type
*/
public interface Map<K, V> {
/**
* Removes all mappings from this map.
*
* O(table length)
*/
public void clear();
/**
* Determines whether this map contains the specified key.
*
* O(1)
*
* @param key
* @return true if this map contains the key, false otherwise
*/
public boolean containsKey(K key);
/**
* Determines whether this map contains the specified value.
*
* O(table length)
*
* @param value
* @return true if this map contains one or more keys to the specified value,
* false otherwise
*/
public boolean containsValue(V value);
/**
* Returns a List view of the mappings contained in this map, where the ordering of
* mapping in the list is insignificant.
*
* O(table length)
*
* @return a List object containing all mapping (i.e., entries) in this map
*/
public List<MapEntry<K, V>> entries();
/**
* Gets the value to which the specified key is mapped.
*
* O(1)
*
* @param key
* @return the value to which the specified key is mapped, or null if this map
* contains no mapping for the key
*/
public V get(K key);
/**
* Determines whether this map contains any mappings.
*
* O(1)
*
* @return true if this map contains no mappings, false otherwise
*/
public boolean isEmpty();
/**
* Associates the specified value with the specified key in this map.
* (I.e., if the key already exists in this map, resets the value;
* otherwise adds the specified key-value pair.)
*
* O(1)
*
* @param key
* @param value
* @return the previous value associated with key, or null if there was no
* mapping for key
*/
public V put(K key, V value);
/**
* Removes the mapping for a key from this map if it is present.
*
* O(1)
*
* @param key
* @return the previous value associated with key, or null if there was no
* mapping for key
*/
public V remove(K key);
/**
* Determines the number of mappings in this map.
*
* O(1)
*
* @return the number of mappings in this map
*/
public int size();
}