Class IntHashMap
- Author:
- Justin Couch, Alex Chaffee (alex@apache.org), Stephen Colebourne, Cristian Frăsinaru
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, empty hashtable with a default capacity and load factor, which is20and0.75respectively.IntHashMap(int initialCapacity) Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is0.75.IntHashMap(int initialCapacity, float loadFactor) Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.IntHashMap(IntHashMap other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears this hashtable so that it contains no keys.booleancontainsKey(int key) Tests if the specified object is a key in this hashtable.booleancontainsValue(int value) Tests if some key maps into the specified value in this hashtable.intget(int key) Returns the value to which the specified key is mapped in this map.intgetOrDefault(int key, int defaultValue) booleanisEmpty()Tests if this hashtable maps no keys to values.int[]keys()final intput(int key, int value) Maps the specifiedkeyto the specifiedvaluein this hashtable.protected voidrehash()Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.intremove(int key) Removes the key (and its corresponding value) from this hashtable.intsize()Returns the number of keys in this hashtable.toString()int[]values()
-
Field Details
-
NONE
public static final int NONE- See Also:
-
-
Constructor Details
-
IntHashMap
public IntHashMap()Constructs a new, empty hashtable with a default capacity and load factor, which is
20and0.75respectively. -
IntHashMap
public IntHashMap(int initialCapacity) Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is
0.75.- Parameters:
initialCapacity- the initial capacity of the hashtable.- Throws:
IllegalArgumentException- if the initial capacity is less than zero.
-
IntHashMap
public IntHashMap(int initialCapacity, float loadFactor) Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.
- Parameters:
initialCapacity- the initial capacity of the hashtable.loadFactor- the load factor of the hashtable.- Throws:
IllegalArgumentException- if the initial capacity is less than zero, or if the load factor is nonpositive.
-
IntHashMap
Copy constructor.- Parameters:
other- theIntHashMapobject that will be copied.
-
-
Method Details
-
size
public int size()Returns the number of keys in this hashtable.
- Returns:
- the number of keys in this hashtable.
-
isEmpty
public boolean isEmpty()Tests if this hashtable maps no keys to values.
- Returns:
trueif this hashtable maps no keys to values;falseotherwise.
-
containsValue
public boolean containsValue(int value) Tests if some key maps into the specified value in this hashtable. This operation is more expensive than the
containsKeymethod.Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).
- Parameters:
value- a value to search for.- Returns:
trueif and only if some key maps to thevalueargument in this hashtable as determined by theequalsmethod;falseotherwise.- Throws:
NullPointerException- if the value isnull.
-
containsKey
public boolean containsKey(int key) Tests if the specified object is a key in this hashtable.
- Parameters:
key- possible key.- Returns:
trueif and only if the specified object is a key in this hashtable, as determined by theequalsmethod;falseotherwise.
-
get
public int get(int key) Returns the value to which the specified key is mapped in this map.
- Parameters:
key- a key in the hashtable.- Returns:
- the value to which the key is mapped in this hashtable;
nullif the key is not mapped to any value in this hashtable.
-
getOrDefault
public int getOrDefault(int key, int defaultValue) - Parameters:
key- a key.defaultValue- the returned value if the key is not in the hashtable.- Returns:
- the value to which the key is mapped in this hashtable, or the default value if the key is not in the hashtable.
-
rehash
protected void rehash()Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.
This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.
-
put
public final int put(int key, int value) Maps the specified
keyto the specifiedvaluein this hashtable. The key cannot benull.The value can be retrieved by calling the
getmethod with a key that is equal to the original key.- Parameters:
key- the hashtable key.value- the value.- Returns:
- the previous value of the specified key in this hashtable, or
nullif it did not have one. - Throws:
NullPointerException- if the key isnull.
-
remove
public int remove(int key) Removes the key (and its corresponding value) from this hashtable.
This method does nothing if the key is not present in the hashtable.
- Parameters:
key- the key that needs to be removed.- Returns:
- the value to which the key had been mapped in this hashtable, or
nullif the key did not have a mapping.
-
clear
public void clear()Clears this hashtable so that it contains no keys.
-
keys
public int[] keys()- Returns:
- the keys in the hash table.
-
values
public int[] values()- Returns:
- the values in the hash table.
-
toString
-