Freigeben über


KeyedItemHashMap<T> Class

  • java.lang.Object
    • com.microsoft.cognitiveservices.speech.util.KeyedItemHashMap<T>

Type Parameters

T

Implements

java.util.Map<java.lang.String,T>

public final class KeyedItemHashMap
implements java.util.Map<java.lang.String,T>

Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, 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 the KeyedItem interface and provide a unique ID to avoid collisions within the map. For more details see the HashMap class.

Constructor Summary

Constructor Description
KeyedItemHashMap()

Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).

Method Summary

Modifier and Type Method and Description
void clear()

Removes all of the mappings from this map.

boolean containsKey(Object key)

Returns true if this map contains a mapping for the specified key.

boolean containsValue(Object keyedItem)

Returns true if this map maps a key to the specified value.

java.util.Set<java.util.Map.Entry<java.lang.String,T>> entrySet()

Returns a Set view of the mappings contained in this map.

T get(Object obj)

Returns the string representation of the Object argument.

boolean isEmpty()

Returns true if this map contains no key-value mappings.

java.util.Set<java.lang.String> keySet()

Returns a Set view of the keys contained in this map.

T put(T keyedItem)

Associates the specified value with the keyedItem's ID in this map.

T put(String key, T keyedItem)

Associates the specified value with the keyedItem's ID in this map.

void putAll(Map<? extends String,? extends T> map)

Copies all of the mappings from the specified map to this map.

T remove(Object keyedItem)

Removes the mapping for the specified keyedItem's ID from this map if present.

int size()

Returns the number of key-value mappings in this map.

java.util.Collection<T> values()

Returns a Collection view of the values contained in this map.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

KeyedItemHashMap

public KeyedItemHashMap()

Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).

Method Details

clear

public void clear()

Removes all of the mappings from this map. The map will be empty after this call returns.

containsKey

public boolean containsKey(Object key)

Returns true if this map contains a mapping for the specified key.

Parameters:

key - The key whose presence in this map is to be tested.

Returns:

true if this map contains a mapping for the specified key.

containsValue

public boolean containsValue(Object keyedItem)

Returns true if this map maps a key to the specified value.

Parameters:

keyedItem - value whose presence in this map is to be tested.

Returns:

true if this map maps the value to an id of an item.

entrySet

public Set> entrySet()

Returns a Set view 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 own remove operation, or through the setValue operation 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 the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:

a set view of the mappings contained in this map

get

public T get(Object obj)

Returns the string representation of the Object argument.

Parameters:

obj - an Object.

Returns:

if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned.

isEmpty

public boolean isEmpty()

Returns true if this map contains no key-value mappings.

Returns:

true if this map contains no key-value mappings.

keySet

public Set keySet()

Returns a Set view 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 own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:

a set view of the keys contained in this map

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(), or null if there was no mapping for keyedItem.getId(). (A null return can also indicate that the map previously associated null with keyedItem.getId().)

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.

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(), or null if there was no mapping for keyedItem.getId(). (A null return can also indicate that the map previously associated null with keyedItem.getId().)

putAll

public void putAll(Map 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.

Parameters:

map - mappings to be stored in this map

remove

public T remove(Object keyedItem)

Removes the mapping for the specified keyedItem's ID from this map if present.

Parameters:

keyedItem - KeyedItem whose mapping is to be removed from the map.

Returns:

the previous value associated with keyedItem.getId(), or null if there was no mapping for keyedItem.getId(). (A null return can also indicate that the map previously associated null with keyedItem.getId().)

size

public int size()

Returns the number of key-value mappings in this map.

Returns:

The number of key-value mappings in this map.

values

public Collection values()

Returns a Collection view 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 own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:

a view of the values contained in this map

Applies to