Bali Share 1.1.18

oracle.bali.share.collection
Class OptimisticHashMap

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--oracle.bali.share.collection.OptimisticHashMap
All Implemented Interfaces:
java.lang.Cloneable

public class OptimisticHashMap
extends java.util.Dictionary
implements java.lang.Cloneable

A Dictionary implementation that behaves like a Hashtable with optimistic synchronization of gets. This results in the following behavior:

  1. Hits on gets are unsynchronized
  2. Misses on gets are retried with synchronization on, resulting in slower behavior than a fully synchronized Hashtable
  3. Rehashing is slower and may happen more often
  4. Removed entries aren't removed until the OptimisticHashMap is rehashed or cloned, but the reference to the value is removed immediately.


Constructor Summary
OptimisticHashMap()
          Constructs a new, empty OptimisticHashMap with a default capacity and load factor, which is 0.75.
OptimisticHashMap(int initialCapacity)
          Constructs a new, empty OptimisticHashMap with the specified initial capacity and default load factor, which is 0.75.
OptimisticHashMap(int initialCapacity, float loadFactor)
          Constructs a new, empty OptimisticHashMap with the specified initial capacity and the specified load factor.
 
Method Summary
 void clear()
          Clears this hashtable so that it contains no keys.
 java.lang.Object clone()
          Creates a shallow copy of this OptimisticHashMap.
 boolean contains(java.lang.Object value)
          Tests if some key maps into the specified value in this hashtable.
 boolean containsKey(java.lang.Object key)
          Tests if the specified object is a key in this hashtable.
 java.util.Enumeration elements()
          Returns an enumeration of the values in this hashtable.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the specified key is mapped in this hashtable.
 boolean isEmpty()
          Tests if this hashtable maps no keys to values.
 java.util.Enumeration keys()
          Returns an enumeration of the keys in this hashtable.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Maps the specified key to the specified value in this hashtable.
protected  void rehash()
          Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.
 java.lang.Object remove(java.lang.Object key)
          Removes the key (and its corresponding value) from this hashtable.
 int size()
          Returns the number of keys in this hashtable.
 java.lang.String toString()
          Returns a string representation of this OptimisticHashMap object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OptimisticHashMap

public OptimisticHashMap(int initialCapacity,
                         float loadFactor)
Constructs a new, empty OptimisticHashMap with the specified initial capacity and the specified load factor.
Parameters:
initialCapacity - the initial capacity of the hashtable.
loadFactor - the load factor of the hashtable.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.

OptimisticHashMap

public OptimisticHashMap(int initialCapacity)
Constructs a new, empty OptimisticHashMap with the specified initial capacity and default load factor, which is 0.75.
Parameters:
initialCapacity - the initial capacity of the hashtable.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than zero.

OptimisticHashMap

public OptimisticHashMap()
Constructs a new, empty OptimisticHashMap with a default capacity and load factor, which is 0.75.
Method Detail

size

public int size()
Returns the number of keys in this hashtable.
Overrides:
size in class java.util.Dictionary
Returns:
the number of keys in this hashtable.

isEmpty

public boolean isEmpty()
Tests if this hashtable maps no keys to values.
Overrides:
isEmpty in class java.util.Dictionary
Returns:
true if this hashtable maps no keys to values; false otherwise.

keys

public java.util.Enumeration keys()
Returns an enumeration of the keys in this hashtable.
Overrides:
keys in class java.util.Dictionary
Returns:
an enumeration of the keys in this hashtable.
See Also:
Enumeration

elements

public java.util.Enumeration elements()
Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.
Overrides:
elements in class java.util.Dictionary
Returns:
an enumeration of the values in this hashtable.
See Also:
Enumeration, keys()

contains

public boolean contains(java.lang.Object value)
Tests if some key maps into the specified value in this hashtable. This operation is more expensive than the containsKey method.

Parameters:
value - a value to search for.
Returns:
true if and only if some key maps to the value argument in this hashtable as determined by the equals method; false otherwise.
Throws:
NullPointerException - if the value is null.
See Also:
containsKey(Object)

containsKey

public boolean containsKey(java.lang.Object key)
Tests if the specified object is a key in this hashtable.
Parameters:
key - possible key.
Returns:
true if and only if the specified object is a key in this hashtable, as determined by the equals method; false otherwise.
See Also:
contains(Object)

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable.
Overrides:
get in class java.util.Dictionary
Parameters:
key - a key in the hashtable.
Returns:
the value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
See Also:
put(Object, Object)

rehash

protected void rehash()
Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Overrides:
put in class java.util.Dictionary
Parameters:
key - the hashtable key.
value - the value.
Returns:
The old value if replacing
Throws:
NullPointerException - if the key or value is null.
See Also:
Object.equals(Object), get(Object)

remove

public java.lang.Object remove(java.lang.Object key)
Removes the key (and its corresponding value) from this hashtable.
Overrides:
remove in class java.util.Dictionary
Parameters:
key - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.

clear

public void clear()
Clears this hashtable so that it contains no keys.

clone

public java.lang.Object clone()
Creates a shallow copy of this OptimisticHashMap. All the structure of the hashtable itself is copied, but the keys and values are not cloned. This is a relatively expensive operation.
Overrides:
clone in class java.lang.Object
Returns:
a clone of the hashtable.

toString

public java.lang.String toString()
Returns a string representation of this OptimisticHashMap object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space). Each entry is rendered as the key, an equals sign =, and the associated element, where the toString method is used to convert the key and element to strings.

Overrides to toString method of Object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this hashtable.

Bali Share 1.1.18