edu.neu.ccs.quick
Class QuickHashMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended byedu.neu.ccs.quick.QuickHashMap
All Implemented Interfaces:
Cloneable, Map, Serializable

public class QuickHashMap
extends HashMap

QuickHashMap extends HashMap by adding one constructor and three methods putPairs, setPairs, and removeKeys that handle an array of Object at once.

In addition, symmetric methods are added that will hash both a key to its value and a value to its key.

All constructors of the original HashMap class are provided as well.

No changes are made to the internal data structure or to any inherited methods.

Since:
2.3
Version:
2.3
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.HashMap
 
Nested classes inherited from class java.util.AbstractMap
 
Field Summary
 
Fields inherited from class java.util.HashMap
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
QuickHashMap()
          A constructor that delegates to class HashMap.
QuickHashMap(int initialCapacity)
          A constructor that delegates to class HashMap.
QuickHashMap(int initialCapacity, float loadFactor)
          A constructor that delegates to class HashMap.
QuickHashMap(Map m)
          A constructor that delegates to class HashMap.
QuickHashMap(Object[][] pairs)
          Constructor that adds the given 2-dimensional array of key-value pairs one-by-one to the hash map.
 
Method Summary
 void putPairs(Object[][] pairs)
          Method that adds the given 2-dimensional array of key-value pairs one-by-one to the hash map.
 void putPairsSymmetric(Object[][] pairs)
          Method that adds the given 2-dimensional array of key-value pairs one-by-one symmetrically to the hash map.
 void putSymmetric(Object key, Object value)
          Method that adds the key-value pair symmetrically to the hash map, that is, the key maps to the value and the value maps to the key.
 void removeKeys(Object[] keys)
          Method that removes the given array of keys one-by-one from the hash map.
 void setPairs(Object[][] pairs)
          Method that first clears this hash map of any existing pairs and then adds the given array of pairs one-by-one to the hash map.
 void setPairsSymmetric(Object[][] pairs)
          Method that first clears this hash map of any existing pairs and then adds the given array of pairs one-by-one symmetrically to the hash map.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

QuickHashMap

public QuickHashMap()
A constructor that delegates to class HashMap.


QuickHashMap

public QuickHashMap(int initialCapacity)
A constructor that delegates to class HashMap.


QuickHashMap

public QuickHashMap(int initialCapacity,
                    float loadFactor)
A constructor that delegates to class HashMap.


QuickHashMap

public QuickHashMap(Map m)
A constructor that delegates to class HashMap.


QuickHashMap

public QuickHashMap(Object[][] pairs)

Constructor that adds the given 2-dimensional array of key-value pairs one-by-one to the hash map.

The capacity is set either to 10 or to 1.5 times the length of the array pairs whichever is larger.

The load factor is set to the default of 0.75.

Parameters:
pairs - the array of pairs to add to this hash map
See Also:
putPairs(Object[][])
Method Detail

putPairs

public void putPairs(Object[][] pairs)

Method that adds the given 2-dimensional array of key-value pairs one-by-one to the hash map.

If pairs is null, then does nothing.

Ignores any subarray pairs[i] that is null or not of length 2.

Parameters:
pairs - the array of pairs to add to this hash map
See Also:
QuickHashMap(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

setPairs

public void setPairs(Object[][] pairs)

Method that first clears this hash map of any existing pairs and then adds the given array of pairs one-by-one to the hash map.

If pairs is null, then this method is equivalent to the inherited method clear.

Ignores any subarray pairs[i] that is null or not of length 2.

Parameters:
pairs - the array of pairs to add to this hash map after clearance
See Also:
putPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

removeKeys

public void removeKeys(Object[] keys)

Method that removes the given array of keys one-by-one from the hash map.

If keys is null, then does nothing.

Parameters:
keys - the array of keys to remove from this hash map
See Also:
putPairs(Object[][]), setPairs(Object[][]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

putSymmetric

public void putSymmetric(Object key,
                         Object value)

Method that adds the key-value pair symmetrically to the hash map, that is, the key maps to the value and the value maps to the key.

Parameters:
key - the key in the key-value pair
value - the value in the key-value pair
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

putPairsSymmetric

public void putPairsSymmetric(Object[][] pairs)

Method that adds the given 2-dimensional array of key-value pairs one-by-one symmetrically to the hash map.

If pairs is null, then does nothing.

Ignores any subarray pairs[i] that is null or not of length 2.

Parameters:
pairs - the array of pairs to add symmetrically to this hash map
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), setPairsSymmetric(Object[][])

setPairsSymmetric

public void setPairsSymmetric(Object[][] pairs)

Method that first clears this hash map of any existing pairs and then adds the given array of pairs one-by-one symmetrically to the hash map.

If pairs is null, then this method is equivalent to the inherited method clear.

Ignores any subarray pairs[i] that is null or not of length 2.

Parameters:
pairs - the array of pairs to add symmetrically to this hash map after clearance
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][])