Package dsa.lab04.base
Interface Map<Key,Value>
- Type Parameters:
Key
- the key typeValue
- the value type
- All Known Subinterfaces:
OrderedMap<Key,
Value>
- All Known Implementing Classes:
ArrayMap
,ArrayMap
,AVLTree
,AVLTree
,BinarySearchTree
,BinarySearchTree
,ChainingHashMap
,ChainingHashMap
,ProbingHashMap
,ProbingHashMap
,SortedArrayMap
,SortedArrayMap
A map.
A container where the items have unique keys. An item consists of a key and a value. The key is the uniquely identifying part of the item. The value is everything else.
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
containsKey
(Key key) Check if the given key is equal to any of those contained.default boolean
containsValue
(Value value) Check if the given value is equal to any of those contained.Find the item with the given key.default Value
Get the value associated with the given key.void
Insert the given item.default void
Insert an item with the given key and value.keys()
Get an iterable that yields each key once.Remove and return the item with the given key.values()
Get an iterable that yields each value once.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
find
Find the item with the given key.- Parameters:
key
- the item's key- Returns:
- the item
- Throws:
NoSuchElementException
- if no item has keykey
-
insert
Insert the given item.If there's already an item with the same key, that item is replaced with this one.
This means that if the key was not already contained, the size is incremented, otherwise it isn't.
- Parameters:
item
- the item
-
insert
Insert an item with the given key and value.If there's already an item with the same key, that item is replaced with this one.
This means that if the key was not already contained, the size is incremented, otherwise it isn't.
- Parameters:
key
- the item's keyvalue
- the item's value
-
remove
Remove and return the item with the given key.Decrements the size (assuming the item was actually in the map).
- Parameters:
key
- the item's key- Returns:
- the item
- Throws:
NoSuchElementException
- ifkey
is not contained
-
containsKey
Check if the given key is equal to any of those contained.- Parameters:
key
- the key to check for membership- Returns:
- whether such a key is contained
-
containsValue
Check if the given value is equal to any of those contained.- Parameters:
value
- the value to check for membership- Returns:
- whether such a value is contained
-
get
Get the value associated with the given key.- Parameters:
key
- the key- Returns:
- the corresponding value
- Throws:
NoSuchElementException
- ifkey
is not contained
-
keys
Get an iterable that yields each key once.- Returns:
- an iterable over the keys
-
values
Get an iterable that yields each value once.- Returns:
- an iterable over the values
-