danbikel.util
Class HashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
danbikel.util.HashMap<K,V>
- All Implemented Interfaces:
- FlexibleMap<K,V>, Serializable, Cloneable, Map<K,V>
public class HashMap<K,V>
- extends AbstractMap<K,V>
- implements FlexibleMap<K,V>, Cloneable, Serializable
Home-grown implementation of a hash map, in order to support the FlexibleMap
interface.
- See Also:
- Serialized Form
maxCapacity
protected static final BigInteger maxCapacity
HashMap
public HashMap()
HashMap
public HashMap(int initialCapacity)
HashMap
public HashMap(int initialCapacity,
float loadFactor)
HashMap
public HashMap(Map<? extends K,? extends V> map)
put
public V put(K key,
V value)
- Specified by:
put
in interface Map<K,V>
- Overrides:
put
in class AbstractMap<K,V>
remove
public V remove(Object key)
- Specified by:
remove
in interface Map<K,V>
- Overrides:
remove
in class AbstractMap<K,V>
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interface Map<K,V>
- Overrides:
containsKey
in class AbstractMap<K,V>
get
public V get(Object key)
- Specified by:
get
in interface Map<K,V>
- Overrides:
get
in class AbstractMap<K,V>
get
public V get(Object key,
int keyHash)
- Description copied from interface:
FlexibleMap
- Returns the value for the specified key. If the specified hash code
is not the value of
key.hashCode()
, the behavior of thiscollins
method is not defined.
- Specified by:
get
in interface FlexibleMap<K,V>
- Parameters:
key
- the key whose value is to be looked upkeyHash
- the value of key.hashCode()
getEntry
public Map.Entry<K,V> getEntry(Object key)
clear
public void clear()
- Specified by:
clear
in interface Map<K,V>
- Overrides:
clear
in class AbstractMap<K,V>
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface Map<K,V>
- Overrides:
isEmpty
in class AbstractMap<K,V>
getCapacity
public int getCapacity()
- Gets the capacity of this map (optional operation).
- Specified by:
getCapacity
in interface FlexibleMap<K,V>
- Returns:
- the capacity of this map (the number of buckets, in the case of a
hash map)
- Throws:
UnsupportedOperationException
- if this map is not a hash map
getLoadFactor
public float getLoadFactor()
- Gets the load factor of this map (optional operation).
- Specified by:
getLoadFactor
in interface FlexibleMap<K,V>
- Returns:
- the load factor of this map
- Throws:
UnsupportedOperationException
- if this map is not a hash map
getMaxBucketSize
public int getMaxBucketSize()
getNumNonEmptyBuckets
public int getNumNonEmptyBuckets()
getAverageBucketSize
public double getAverageBucketSize(boolean onlyCountNonEmptyBuckets)
getStats
public String getStats()
- Returns a string that represents the useful statistics of this map
(useful/necessary in the case of hash maps, where it is desirable to know
the number of collisions and average and maximum buckets sizes). The format
of the string is up to the implementor.
- Specified by:
getStats
in interface FlexibleMap<K,V>
entrySet
public Set<Map.Entry<K,V>> entrySet()
- Specified by:
entrySet
in interface Map<K,V>
- Specified by:
entrySet
in class AbstractMap<K,V>
main
public static void main(String[] args)
Author: Dan Bikel.