Interface Map<K,V>
-
- All Known Implementing Classes:
BSTMap
public interface Map<K,V>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
containsKey(K key)
Returns true if the key has been put into this map (and not removed).V
get(K key)
Retrieves the value associated with the given key.void
put(K key, V value)
Associates the given value to the given key.void
remove(K key)
Removes the key and any associated value from the map, if present.int
size()
Returns the number of distinct keys that have been put in the map (and not yet removed).java.util.Deque<K>
traverse()
Returns a new Deque with all of the keys of this map.
-
-
-
Method Detail
-
get
V get(K key)
Retrieves the value associated with the given key. If the key is not in the map, null is returned.
-
containsKey
boolean containsKey(K key)
Returns true if the key has been put into this map (and not removed).
-
put
void put(K key, V value)
Associates the given value to the given key. If the key was not in the map, it is added and the size increases. Otherwise the size stays the same, but the new value should update the value previously associated to that key.
-
remove
void remove(K key)
Removes the key and any associated value from the map, if present. If the key is not in the map, nothing happens (no error should be raised). This method is optional; the default just throws an exception.
-
size
int size()
Returns the number of distinct keys that have been put in the map (and not yet removed).
-
traverse
java.util.Deque<K> traverse()
Returns a new Deque with all of the keys of this map. When feasible based on the underlying data structure (such as a binary search tree), the keys should be added to the tail end of the Deque in sorted order.
-
-