Class jgl.HashMap
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jgl.HashMap

java.lang.Object
   |
   +----java.util.Dictionary
           |
           +----jgl.HashMap

public class HashMap
extends Dictionary
implements Container
A HashMap is an associative container that manages a set of key/value pairs. A pair is stored in a hashing structure based on the hash code of its key, which is obtained by using the standard hashCode() function. A HashMap can be set to allow duplicate keys. Keys are matched using a BinaryPredicate which is EqualTo() by default. The default is to not allow duplicate keys.

A HashMap is useful for implementing a collection of one-to-one or one-to-many mappings.

Insertion can invalidate iterators.

Removal can invalidate iterators.

See Also:
HashMapExamples

Constructor Index

 o HashMap()
Construct myself to be an empty HashMap that compares key using equals() and does not allow duplicates.
 o HashMap(BinaryPredicate)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate and does not allow duplicates.
 o HashMap(BinaryPredicate, boolean)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate and conditionally allows duplicates.
 o HashMap(BinaryPredicate, boolean, int, float)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate and conditionally allows duplicates.
 o HashMap(boolean)
Construct myself to be an empty HashMap that compares keys using equals() and conditionally allows duplicates.
 o HashMap(HashMap)
Construct myself to be a shallow copy of an existing HashMap.

Method Index

 o add(Object)
Assume that the specified object is a Pair whose first field is a key and whose second field is a value.
 o add(Object, Object)
If the key doesn't exist or duplicates are allowed, associate the value with the key and return null, otherwise don't modify the map and return the current value associated with the key.
 o allowsDuplicates()
Return true if I allow duplicate keys.
 o begin()
Return an iterator positioned at my first pair.
 o clear()
Remove all of my elements.
 o clone()
Return a shallow copy of myself.
 o copy(HashMap)
Become a shallow copy of an existing HashMap.
 o count(Object)
Return the number of key/value pairs that match a particular key.
 o countValues(Object)
Return the number of values that match a given object.
 o elements()
Return an Enumeration to my values.
 o end()
Return an iterator positioned immediately after my last pair.
 o equalRange(Object)
Return a range whose first element is an iterator positioned at the first occurence of a specific key and whose second element is an iterator positioned immediately after the last occurence of that key.
 o equals(HashMap)
Return true if I contain exactly the same key/value pairs as another HashMap.
 o equals(Object)
Return true if I'm equal to another object.
 o find(Object)
Find the first key/value pair based on its key and return its position.
 o finish()
Return an iterator positioned immediately afer my last pair.
 o get(Object)
Return the value associated with key, or null if the key does not exist.
 o getComparator()
Return my comparator.
 o getLoadRatio()
Return my load ratio.
 o hashCode()
Return my hash code for support of hashing containers
 o isEmpty()
Return true if I contain no entries.
 o keys()
Return an Enumeration of all my keys.
 o keys(Object)
Return an Enumeration of all my keys that are associated with a particular value.
 o maxSize()
Return the maximum number of entries that I can contain.
 o put(Object, Object)
If the key doesn't exist, associate the value with the key and return null, otherwise replace the first value associated with the key and return the old value.
 o remove(Enumeration)
Remove the element at a particular position.
 o remove(Enumeration, Enumeration)
Remove the elements within a specified range.
 o remove(Object)
Remove all key/value pairs that match a particular key.
 o size()
Return the number of entries that I contain.
 o start()
Return an iterator positioned at my first pair.
 o swap(HashMap)
Swap my contents with another HashMap.
 o toString()
Return a string that describes me.
 o values(Object)
Return an Enumeration of all my values that are associated with a particular key.

Constructors

 o HashMap
  public HashMap()
Construct myself to be an empty HashMap that compares key using equals() and does not allow duplicates.
 o HashMap
  public HashMap(boolean allowDuplicates)
Construct myself to be an empty HashMap that compares keys using equals() and conditionally allows duplicates.
Parameters:
allowDuplicates - true if duplicates are allowed.
 o HashMap
  public HashMap(BinaryPredicate comparator)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate and does not allow duplicates.
Parameters:
comparator - The predicate for comparing keys.
 o HashMap
  public HashMap(BinaryPredicate comparator,
                 boolean allowDuplicates)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate and conditionally allows duplicates.
Parameters:
comparator - The predicate for comparing keys.
allowDuplicates - true if duplicates are allowed.
 o HashMap
  public HashMap(BinaryPredicate comparator,
                 boolean allowDuplicates,
                 int capacity,
                 float loadRatio)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate and conditionally allows duplicates. The initial buckets and load ratio must also be specified.
Parameters:
comparator - The predicate for comparing keys.
allowDuplicates - true if duplicates are allowed.
capacity - The initial number of hash buckets to reserve.
loadRatio - The maximum load ratio.
 o HashMap
  public HashMap(HashMap map)
Construct myself to be a shallow copy of an existing HashMap.
Parameters:
map - The HashMap to copy.

Methods

 o allowsDuplicates
  public boolean allowsDuplicates()
Return true if I allow duplicate keys.
 o getComparator
  public BinaryPredicate getComparator()
Return my comparator.
 o getLoadRatio
  public float getLoadRatio()
Return my load ratio.
 o clone
  public synchronized Object clone()
Return a shallow copy of myself.
Overrides:
clone in class Object
 o copy
  public synchronized void copy(HashMap map)
Become a shallow copy of an existing HashMap.
Parameters:
map - The HashMap that I shall become a shallow copy of.
 o toString
  public synchronized String toString()
Return a string that describes me.
Overrides:
toString in class Object
 o elements
  public synchronized Enumeration elements()
Return an Enumeration to my values.
Overrides:
elements in class Dictionary
 o start
  public synchronized ForwardIterator start()
Return an iterator positioned at my first pair.
 o finish
  public synchronized ForwardIterator finish()
Return an iterator positioned immediately afer my last pair.
 o begin
  public synchronized HashMapIterator begin()
Return an iterator positioned at my first pair.
 o end
  public synchronized HashMapIterator end()
Return an iterator positioned immediately after my last pair.
 o isEmpty
  public boolean isEmpty()
Return true if I contain no entries.
Overrides:
isEmpty in class Dictionary
 o size
  public int size()
Return the number of entries that I contain.
Overrides:
size in class Dictionary
 o maxSize
  public int maxSize()
Return the maximum number of entries that I can contain.
 o equals
  public boolean equals(Object object)
Return true if I'm equal to another object.
Parameters:
object - The object to compare myself against.
Overrides:
equals in class Object
 o equals
  public synchronized boolean equals(HashMap map)
Return true if I contain exactly the same key/value pairs as another HashMap. Use equals() to compare values.
Parameters:
map - The HashMap to compare myself against.
 o hashCode
  public int hashCode()
Return my hash code for support of hashing containers
Overrides:
hashCode in class Object
 o swap
  public synchronized void swap(HashMap map)
Swap my contents with another HashMap.
Parameters:
map - The HashMap that I will swap my contents with.
 o clear
  public synchronized void clear()
Remove all of my elements.
 o remove
  public synchronized Object remove(Object key)
Remove all key/value pairs that match a particular key.
Parameters:
key - The key of the pair(s) to be removed.
Returns:
Return the value associated with the first key found or null if key was not found.
Overrides:
remove in class Dictionary
 o remove
  public synchronized void remove(Enumeration e)
Remove the element at a particular position.
Parameters:
e - An Enumeration positioned at the element to remove.
Throws: IllegalArgumentException
is the Enumeration isn't a HashMapIterator for this HashMap object.
 o remove
  public synchronized void remove(Enumeration first,
                                  Enumeration last)
Remove the elements within a specified range.
Parameters:
first - An Enumeration positioned at the first element to remove.
last - An Enumeration positioned immediately after the last element to remove.
Throws: IllegalArgumentException
is the Enumeration isn't a HashMapIterator for this HashMap object.
 o find
  public synchronized HashMapIterator find(Object key)
Find the first key/value pair based on its key and return its position. If the key is not found, return end().
Parameters:
key - The key to locate.
 o count
  public int count(Object key)
Return the number of key/value pairs that match a particular key.
Parameters:
key - The key to match against.
 o countValues
  public synchronized int countValues(Object value)
Return the number of values that match a given object.
Parameters:
value - The value to match against.
 o get
  public synchronized Object get(Object key)
Return the value associated with key, or null if the key does not exist.
Parameters:
key - The key to search against.
Overrides:
get in class Dictionary
 o put
  public synchronized Object put(Object key,
                                 Object value)
If the key doesn't exist, associate the value with the key and return null, otherwise replace the first value associated with the key and return the old value.
Parameters:
key - The key.
value - The value.
Throws: NullPointerException
If the key or value are equal to null
Overrides:
put in class Dictionary
 o add
  public Object add(Object object)
Assume that the specified object is a Pair whose first field is a key and whose second field is a value. If the key doesn't exist or duplicates are allowed, associate the value with the key and return null, otherwise don't modify the map and return the current value associated with the key.
Parameters:
object - The pair to add.
Throws: IllegalArgumentException
If the object is not a Pair
Throws: NullPointerException
If the object is null or if the first or second items in the pair are null.
 o add
  public Object add(Object key,
                    Object value)
If the key doesn't exist or duplicates are allowed, associate the value with the key and return null, otherwise don't modify the map and return the current value associated with the key.
Parameters:
key - The key.
value - The value.
Throws: NullPointerException
If the key or value is null.
 o keys
  public synchronized Enumeration keys()
Return an Enumeration of all my keys.
Overrides:
keys in class Dictionary
 o keys
  public synchronized Enumeration keys(Object value)
Return an Enumeration of all my keys that are associated with a particular value.
Parameters:
value - The value to match.
 o values
  public synchronized Enumeration values(Object key)
Return an Enumeration of all my values that are associated with a particular key.
Parameters:
key - The key to match.
 o equalRange
  public synchronized Range equalRange(Object key)
Return a range whose first element is an iterator positioned at the first occurence of a specific key and whose second element is an iterator positioned immediately after the last occurence of that key. Note that all key inbetween these iterators will also match the specified key. If no matching key is found, return null.
Parameters:
object - The key whose bounds are to be found.

All Packages  Class Hierarchy  This Package  Previous  Next  Index