Class StringToIntMap
java.lang.Object
it.unimi.di.prog2.s12.StringToIntMap
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all of the mappings from this map.booleancontainsKey(String key) Returns if this map contains the specified key.booleancontainsValue(int value) Returns if this map contains the specified value.private static intdichotomicSearch(List<String> haystack, String needle) Finds the index (or insertion point) of a string in a list of strings kept in increasing lexicographyc order.booleanintReturns the value to which the specified key is mapped.inthashCode()booleanisEmpty()Returns if this map is empty.voidAssociates in this map the new key with the specified value.booleanRemoves the mapping for a key from this map if it is present.intsize()Returns the size of this map.toString()
-
Field Details
-
keys
-
values
-
-
Constructor Details
-
StringToIntMap
public StringToIntMap()Creates a new empty map.
-
-
Method Details
-
size
public int size()Returns the size of this map.- Returns:
- the number of key-value mappings in this map.
-
isEmpty
public boolean isEmpty()Returns if this map is empty.- Returns:
trueiff this map contains no key-value mappings.
-
dichotomicSearch
Finds the index (or insertion point) of a string in a list of strings kept in increasing lexicographyc order.If the list contains the given string, returns its index. Otherwise, returns
-(insertion_point) - 1whereinsertion_pointis the index of the first string greater thanneedle; note that this implies that the return value is non-negative iff the list contains the string.- Parameters:
haystack- the notnulllist of notnullstrings in increasing degree order.needle- the string to look for, must not benull.- Returns:
- the index of the given string, or
-insertion_point - 1if none is present. - See Also:
-
containsKey
Returns if this map contains the specified key.- Parameters:
key- the key to search for.- Returns:
trueiff this map contains a key-value mappings with the givenkey.
-
containsValue
public boolean containsValue(int value) Returns if this map contains the specified value.- Parameters:
value- the value to search for.- Returns:
trueiff this map contains a key-value mappings with the givenvalue.
-
get
Returns the value to which the specified key is mapped.- Parameters:
key- the key whose associated value is to be returned.- Returns:
- the value to which the specified key is mapped.
- Throws:
NoSuchElementException- if this map contains no mapping for the key, or the key isnull.
-
put
Associates in this map the new key with the specified value.- Parameters:
key- the key with which the specified value is to be associated.value- the value to be associated with the specified key.- Throws:
IllegalArgumentException- if the map already contain a mapping for the key.NullPointerException- if the key isnull.
-
remove
Removes the mapping for a key from this map if it is present.- Parameters:
key- the key whose mapping is to be removed from the map.- Returns:
trueiff this map contained a mapping for the specified key, and hence is modified by this operation.
-
clear
public void clear()Removes all of the mappings from this map. -
equals
-
hashCode
-
toString
-