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
-
HashMap()
- Construct myself to be an empty HashMap that compares key using equals() and
does not allow duplicates.
-
HashMap(BinaryPredicate)
- Construct myself to be an empty HashMap that compares keys using the specified
binary predicate and does not allow duplicates.
-
HashMap(BinaryPredicate, boolean)
- Construct myself to be an empty HashMap that compares keys using the specified
binary predicate and conditionally allows duplicates.
-
HashMap(BinaryPredicate, boolean, int, float)
- Construct myself to be an empty HashMap that compares keys using the specified
binary predicate and conditionally allows duplicates.
-
HashMap(boolean)
- Construct myself to be an empty HashMap that compares keys using equals() and
conditionally allows duplicates.
-
HashMap(HashMap)
- Construct myself to be a shallow copy of an existing HashMap.
-
add(Object)
- Assume that the specified object is a Pair whose first field is a key and whose
second field is a value.
-
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.
-
allowsDuplicates()
- Return true if I allow duplicate keys.
-
begin()
- Return an iterator positioned at my first pair.
-
clear()
- Remove all of my elements.
-
clone()
- Return a shallow copy of myself.
-
copy(HashMap)
- Become a shallow copy of an existing HashMap.
-
count(Object)
- Return the number of key/value pairs that match a particular key.
-
countValues(Object)
- Return the number of values that match a given object.
-
elements()
- Return an Enumeration to my values.
-
end()
- Return an iterator positioned immediately after my last pair.
-
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.
-
equals(HashMap)
- Return true if I contain exactly the same key/value pairs as another HashMap.
-
equals(Object)
- Return true if I'm equal to another object.
-
find(Object)
- Find the first key/value pair based on its key and return its position.
-
finish()
- Return an iterator positioned immediately afer my last pair.
-
get(Object)
- Return the value associated with key, or null if the key does not exist.
-
getComparator()
- Return my comparator.
-
getLoadRatio()
- Return my load ratio.
-
hashCode()
- Return my hash code for support of hashing containers
-
isEmpty()
- Return true if I contain no entries.
-
keys()
- Return an Enumeration of all my keys.
-
keys(Object)
- Return an Enumeration of all my keys that are associated with a particular value.
-
maxSize()
- Return the maximum number of entries that I can contain.
-
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.
-
remove(Enumeration)
- Remove the element at a particular position.
-
remove(Enumeration, Enumeration)
- Remove the elements within a specified range.
-
remove(Object)
- Remove all key/value pairs that match a particular key.
-
size()
-
Return the number of entries that I contain.
-
start()
- Return an iterator positioned at my first pair.
-
swap(HashMap)
- Swap my contents with another HashMap.
-
toString()
- Return a string that describes me.
-
values(Object)
- Return an Enumeration of all my values that are associated with a particular key.
HashMap
public HashMap()
- Construct myself to be an empty HashMap that compares key using equals() and
does not allow duplicates.
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.
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.
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.
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.
HashMap
public HashMap(HashMap map)
- Construct myself to be a shallow copy of an existing HashMap.
- Parameters:
- map - The HashMap to copy.
allowsDuplicates
public boolean allowsDuplicates()
- Return true if I allow duplicate keys.
getComparator
public BinaryPredicate getComparator()
- Return my comparator.
getLoadRatio
public float getLoadRatio()
- Return my load ratio.
clone
public synchronized Object clone()
- Return a shallow copy of myself.
- Overrides:
- clone in class Object
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.
toString
public synchronized String toString()
- Return a string that describes me.
- Overrides:
- toString in class Object
elements
public synchronized Enumeration elements()
- Return an Enumeration to my values.
- Overrides:
- elements in class Dictionary
start
public synchronized ForwardIterator start()
- Return an iterator positioned at my first pair.
finish
public synchronized ForwardIterator finish()
- Return an iterator positioned immediately afer my last pair.
begin
public synchronized HashMapIterator begin()
- Return an iterator positioned at my first pair.
end
public synchronized HashMapIterator end()
- Return an iterator positioned immediately after my last pair.
isEmpty
public boolean isEmpty()
- Return true if I contain no entries.
- Overrides:
- isEmpty in class Dictionary
size
public int size()
- Return the number of entries that I contain.
- Overrides:
- size in class Dictionary
maxSize
public int maxSize()
- Return the maximum number of entries that I can contain.
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
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.
hashCode
public int hashCode()
- Return my hash code for support of hashing containers
- Overrides:
- hashCode in class Object
swap
public synchronized void swap(HashMap map)
- Swap my contents with another HashMap.
- Parameters:
- map - The HashMap that I will swap my contents with.
clear
public synchronized void clear()
- Remove all of my elements.
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
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.
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.
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.
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.
countValues
public synchronized int countValues(Object value)
- Return the number of values that match a given object.
- Parameters:
- value - The value to match against.
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
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
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.
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.
keys
public synchronized Enumeration keys()
- Return an Enumeration of all my keys.
- Overrides:
- keys in class Dictionary
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.
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.
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