Package dsa.lab04.solutions
Class ArrayMap<Key,Value> 
java.lang.Object
dsa.lab04.solutions.ArrayMap<Key,Value> 
- Type Parameters:
- Key- the key type
- Value- the value type
- All Implemented Interfaces:
- Container<MapItem<Key,,- Value>> - Map<Key,,- Value> - Iterable<MapItem<Key,- Value>> 
An (unsorted) array map.
 
A map implemented using a dynamic array of key-value items.
 find(Key), insert(dsa.lab04.base.MapItem<Key, Value>) and remove(Key) are all O(n),
 where n is the size.
- 
Constructor SummaryConstructorsConstructorDescriptionArrayMap()Construct an empty array map.Construct an array map containing the given items.Construct an array map containing the given items.Construct an array map containing the given items more efficiently thanArrayMap(Iterable).
- 
Method SummaryMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliteratorMethods inherited from interface dsa.lab04.base.MapcontainsKey, containsValue, get, insert, keys, values
- 
Constructor Details- 
ArrayMappublic ArrayMap()Construct an empty array map.
- 
ArrayMapConstruct an array map containing the given items.- Parameters:
- items- the items
 
- 
ArrayMapConstruct an array map containing the given items more efficiently thanArrayMap(Iterable).- Parameters:
- items- the items
- size- the number of items
- Throws:
- IllegalArgumentException- if- size!=- n(where- nis- items's size)
 
- 
ArrayMapConstruct an array map containing the given items.- Parameters:
- items- the items
 
 
- 
- 
Method Details- 
sizepublic int size()Description copied from interface:ContainerGet the number of contained items.
- 
findDescription copied from interface:MapFind the item with the given key.- Specified by:
- findin interface- Map<Key,- Value> 
- Parameters:
- key- the item's key
- Returns:
- the item
- Throws:
- NoSuchElementException- if no item has key- key
 
- 
insertDescription copied from interface:MapInsert 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. 
- 
removeDescription copied from interface:MapRemove and return the item with the given key.Decrements the size (assuming the item was actually in the map). - Specified by:
- removein interface- Map<Key,- Value> 
- Parameters:
- key- the item's key
- Returns:
- the item
- Throws:
- NoSuchElementException- if- keyis not contained
 
- 
itemsDescription copied from interface:ContainerGet an iterable that yields each item once.
 
-