Package com.zybooks.dsaj.map
Class UnsortedTableMap<K,V>
java.lang.Object
com.zybooks.dsaj.map.AbstractMap<K,V>
com.zybooks.dsaj.map.UnsortedTableMap<K,V>
- Type Parameters:
K
- The key type (keys must be unique)V
- The value type
- All Implemented Interfaces:
Map<K,
V>
An implementation of a map using an unsorted table.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.zybooks.dsaj.map.AbstractMap
AbstractMap.MapEntry<K,
V> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionentrySet()
Returns an iterable collection of all key-value entries of the map.Returns the value associated with the specified key, or null if no such entry exists.Associates the given value with the given key.Removes the entry with the specified key, if present, and returns its value.int
size()
Returns the number of entries in the map.Methods inherited from class com.zybooks.dsaj.map.AbstractMap
isEmpty, keySet, values
-
Constructor Details
-
UnsortedTableMap
public UnsortedTableMap()Constructs an initially empty map.
-
-
Method Details
-
size
public int size()Returns the number of entries in the map.- Returns:
- number of entries in the map
-
get
Returns the value associated with the specified key, or null if no such entry exists.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the associated value, or null if no such entry exists
-
put
Associates the given value with the given key. If an entry with the key was already in the map, this replaced the previous value with the new one and returns the old value. Otherwise, a new entry is added and null is returned.- Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key- Returns:
- the previous value associated with the key (or null, if no such entry)
-
remove
Removes the entry with the specified key, if present, and returns its value. Otherwise does nothing and returns null.- Parameters:
key
- the key whose entry is to be removed from the map- Returns:
- the previous value associated with the removed key, or null if no such entry exists
-
entrySet
Returns an iterable collection of all key-value entries of the map.- Returns:
- iterable collection of the map's entries
-