All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class COM.objectspace.jgl.HashMap

java.lang.Object
   |
   +----java.util.Dictionary
           |
           +----COM.objectspace.jgl.Map
                   |
                   +----COM.objectspace.jgl.HashMap

public class HashMap
extends Map
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. Keys are matched by default using a BinaryPredicate that uses equals() for comparisons. Duplicate keys are not allowed unless explicitly specified.

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:
BinaryPredicate, 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(BinaryPredicate, int, float)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate.
 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 allowExpansion(boolean)
Enable or disable the current expansion mode.
 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 expansionAllowed()
Return true if adding an object to myself could result in an expansion of the number of hash buckets I currently use.
 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 lowerBound(Object)
Return an iterator positioned at the first location that a pair with a specified key could be inserted without violating the ordering criteria.
 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 remove(Object, int)
Remove at most a given number of 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 upperBound(Object)
Return an iterator positioned at the last location that a pair with a specified key could be inserted without violating the ordering criteria.
 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,
                int capacity,
                float loadRatio)
Construct myself to be an empty HashMap that compares keys using the specified binary predicate. The initial buckets and load ratio must also be specified.

Parameters:
comparator - The predicate for comparing keys.
capacity - The initial number of hash buckets to reserve.
loadRatio - The maximum load ratio.
 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 Map
 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 Map
 o elements
 public synchronized Enumeration elements()
Return an Enumeration to my values.

Overrides:
elements in class Map
 o start
 public ForwardIterator start()
Return an iterator positioned at my first pair.

Overrides:
start in class Map
 o finish
 public ForwardIterator finish()
Return an iterator positioned immediately afer my last pair.

Overrides:
finish in class Map
 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 Map
 o size
 public int size()
Return the number of entries that I contain.

Overrides:
size in class Map
 o maxSize
 public int maxSize()
Return the maximum number of entries that I can contain.

Overrides:
maxSize in class Map
 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 Map
 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 synchronized 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.

Overrides:
clear in class Map
 o remove
 public 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 first key/value pair removed or null if not changed.
Overrides:
remove in class Dictionary
 o remove
 public int remove(Object key,
                   int count)
Remove at most a given number of key/value pairs that match a particular key.

Parameters:
key - The key of the pair(s) to be removed.
count - The maximum number of the pair(s) to remove.
Returns:
Return the number of pairs removed.
 o remove
 public synchronized Object remove(Enumeration e)
Remove the element at a particular position.

Parameters:
e - An Enumeration positioned at the element to remove.
Returns:
Return the value associated with the enumeration.
Throws: IllegalArgumentException
is the Enumeration isn't a HashMapIterator for this HashMap object.
Overrides:
remove in class Map
 o remove
 public synchronized int 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.
Returns:
Return the number of pairs removed.
Throws: IllegalArgumentException
is the Enumeration isn't a HashMapIterator for this HashMap object.
Overrides:
remove in class Map
 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 synchronized int count(Object key)
Return the number of key/value pairs that match a particular key.

Parameters:
key - The key to match against.
Overrides:
count in class Map
 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.
Overrides:
countValues in class Map
 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.
Overrides:
add in class Map
 o add
 public synchronized 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.
Overrides:
keys in class Map
 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.
Overrides:
values in class Map
 o lowerBound
 public synchronized HashMapIterator lowerBound(Object key)
Return an iterator positioned at the first location that a pair with a specified key could be inserted without violating the ordering criteria. If no such location is found, return an iterator positioned at end().

Parameters:
key - The key.
 o upperBound
 public synchronized HashMapIterator upperBound(Object key)
Return an iterator positioned at the last location that a pair with a specified key could be inserted without violating the ordering criteria. If no such location is found, return an iterator positioned at end().

Parameters:
key - The key.
 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, both ends of the range will be the same.

Parameters:
object - The key whose bounds are to be found.
 o expansionAllowed
 public boolean expansionAllowed()
Return true if adding an object to myself could result in an expansion of the number of hash buckets I currently use.

 o allowExpansion
 public synchronized void allowExpansion(boolean allow)
Enable or disable the current expansion mode. If disabled, no new hash buckets will ever be created regardless of my size.

Parameters:
allow - The new expansion mode.

All Packages  Class Hierarchy  This Package  Previous  Next  Index