Class KeyedItemHashMap<T extends KeyedItem>
- java.lang.Object
-
- com.microsoft.cognitiveservices.speech.util.KeyedItemHashMap<T>
-
public final class KeyedItemHashMap<T extends KeyedItem> extends Object implements Map<String,T>
Hash table based implementation of theMapinterface. This implementation provides all of the optional map operations, and permitsnullvalues and thenullkey. (TheHashMapclass is roughly equivalent toHashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time. Unlike a typical hash map, this implementation uses KeyedItem's as the value. A KeyedItem must implement theKeyedIteminterface and provide a unique ID to avoid collisions within the map. For more details see theHashMapclass.
-
-
Constructor Summary
Constructors Constructor Description KeyedItemHashMap()Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all of the mappings from this map.booleancontainsKey(Object key)Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object keyedItem)Returnstrueif this map maps a key to the specified value.Set<Map.Entry<String,T>>entrySet()Returns aSetview of the mappings contained in this map.Tget(Object obj)Returns the string representation of theObjectargument.booleanisEmpty()Returnstrueif this map contains no key-value mappings.Set<String>keySet()Returns aSetview of the keys contained in this map.Tput(String key, T keyedItem)Associates the specified value with the keyedItem's ID in this map.Tput(T keyedItem)Associates the specified value with the keyedItem's ID in this map.voidputAll(Map<? extends String,? extends T> map)Copies all of the mappings from the specified map to this map.Tremove(Object keyedItem)Removes the mapping for the specified keyedItem's ID from this map if present.intsize()Returns the number of key-value mappings in this map.Collection<T>values()Returns aCollectionview of the values contained in this map.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
size
public int size()
Returns the number of key-value mappings in this map.
-
isEmpty
public boolean isEmpty()
Returnstrueif this map contains no key-value mappings.
-
containsKey
public boolean containsKey(Object key)
Returnstrueif this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap<String,T extends KeyedItem>- Parameters:
key- The key whose presence in this map is to be tested.- Returns:
trueif this map contains a mapping for the specified key.
-
containsValue
public boolean containsValue(Object keyedItem)
Returnstrueif this map maps a key to the specified value.- Specified by:
containsValuein interfaceMap<String,T extends KeyedItem>- Parameters:
keyedItem- value whose presence in this map is to be tested.- Returns:
trueif this map maps the value to an id of an item.
-
put
public T put(String key, T keyedItem)
Associates the specified value with the keyedItem's ID in this map. If the map previously contained a mapping for the keyedItem's ID, the old value is replaced.- Specified by:
putin interfaceMap<String,T extends KeyedItem>- Parameters:
key- UNUSED here but necessary for override.keyedItem- Value that implements the KeyedItem interface. The getId() function will be used to determine the key for the map.- Returns:
- the previous value associated with
keyedItem.getId(), ornullif there was no mapping forkeyedItem.getId(). (Anullreturn can also indicate that the map previously associatednullwithkeyedItem.getId().)
-
put
public T put(T keyedItem)
Associates the specified value with the keyedItem's ID in this map. If the map previously contained a mapping for the keyedItem's ID, the old value is replaced.- Parameters:
keyedItem- Value that implements the KeyedItem interface. The getId() function will be used to determine the key for the map.- Returns:
- the previous value associated with
keyedItem.getId(), ornullif there was no mapping forkeyedItem.getId(). (Anullreturn can also indicate that the map previously associatednullwithkeyedItem.getId().)
-
remove
public T remove(Object keyedItem)
Removes the mapping for the specified keyedItem's ID from this map if present.- Specified by:
removein interfaceMap<String,T extends KeyedItem>- Parameters:
keyedItem- KeyedItem whose mapping is to be removed from the map.- Returns:
- the previous value associated with
keyedItem.getId(), ornullif there was no mapping forkeyedItem.getId(). (Anullreturn can also indicate that the map previously associatednullwithkeyedItem.getId().) - Throws:
ClassCastException- if the keyedItem does not implement the KeyedItem interface.
-
putAll
public void putAll(Map<? extends String,? extends T> map)
Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
-
clear
public void clear()
Removes all of the mappings from this map. The map will be empty after this call returns.
-
keySet
public Set<String> keySet()
Returns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.
-
values
public Collection<T> values()
Returns aCollectionview of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Collection.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.
-
entrySet
public Set<Map.Entry<String,T>> entrySet()
Returns aSetview of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation, or through thesetValueoperation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.
-
-