Parsing Engine

danbikel.util
Class HashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
protected static BigInteger maxCapacity
           
 
Constructor Summary
HashMap()
           
HashMap(int initialCapacity)
           
HashMap(int initialCapacity, float loadFactor)
           
HashMap(Map<? extends K,? extends V> map)
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
 V get(Object key, int keyHash)
          Returns the value for the specified key.
 double getAverageBucketSize(boolean onlyCountNonEmptyBuckets)
           
 int getCapacity()
          Gets the capacity of this map (optional operation).
 Map.Entry<K,V> getEntry(Object key)
           
 float getLoadFactor()
          Gets the load factor of this map (optional operation).
 int getMaxBucketSize()
           
 int getNumNonEmptyBuckets()
           
 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).
 boolean isEmpty()
           
static void main(String[] args)
           
 V put(K key, V value)
           
 V remove(Object key)
           
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, keySet, putAll, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsValue, equals, hashCode, keySet, putAll, size, values
 

Field Detail

maxCapacity

protected static final BigInteger maxCapacity
Constructor Detail

HashMap

public HashMap()

HashMap

public HashMap(int initialCapacity)

HashMap

public HashMap(int initialCapacity,
               float loadFactor)

HashMap

public HashMap(Map<? extends K,? extends V> map)
Method Detail

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 up
keyHash - 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)

Parsing Engine

Author: Dan Bikel.