org.apache.myfaces.trinidadinternal.util
Class OptimisticHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.apache.myfaces.trinidadinternal.util.OptimisticHashMap<K,V>
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map<K,V>

public class OptimisticHashMap<K,V>
extends java.util.AbstractMap<K,V>
implements java.lang.Cloneable

A Map 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.

Version:
$Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/util/OptimisticHashMap.java#0 $) $Date: 10-nov-2005.19:56:01 $
Author:
The Oracle ADF Faces Team

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<V> elements()
          Returns an enumeration of the values in this hashtable.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 V 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<K> keys()
          Returns an enumeration of the keys in this hashtable.
 V put(K key, V 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.
 V 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.util.AbstractMap
containsValue, equals, hashCode, keySet, putAll, values
 
Methods inherited from class java.lang.Object
finalize, getClass, 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

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,V>
Specified by:
entrySet in class java.util.AbstractMap<K,V>

size

public int size()
Returns the number of keys in this hashtable.

Specified by:
size in interface java.util.Map<K,V>
Overrides:
size in class java.util.AbstractMap<K,V>
Returns:
the number of keys in this hashtable.

isEmpty

public boolean isEmpty()
Tests if this hashtable maps no keys to values.

Specified by:
isEmpty in interface java.util.Map<K,V>
Overrides:
isEmpty in class java.util.AbstractMap<K,V>
Returns:
true if this hashtable maps no keys to values; false otherwise.

keys

public java.util.Enumeration<K> keys()
Returns an enumeration of the keys in this hashtable.

Returns:
an enumeration of the keys in this hashtable.
See Also:
Enumeration

elements

public java.util.Enumeration<V> elements()
Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.

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:
java.lang.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.

Specified by:
containsKey in interface java.util.Map<K,V>
Overrides:
containsKey in class java.util.AbstractMap<K,V>
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 V get(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable.

Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.AbstractMap<K,V>
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 V put(K key,
             V 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.

Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.AbstractMap<K,V>
Parameters:
key - the hashtable key.
value - the value.
Returns:
The old value if replacing
Throws:
java.lang.NullPointerException - if the key or value is null.
See Also:
Object.equals(Object), get(Object)

remove

public V remove(java.lang.Object key)
Removes the key (and its corresponding value) from this hashtable.

Specified by:
remove in interface java.util.Map<K,V>
Overrides:
remove in class java.util.AbstractMap<K,V>
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.

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class java.util.AbstractMap<K,V>

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.util.AbstractMap<K,V>
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.util.AbstractMap<K,V>
Returns:
a string representation of this hashtable.


Copyright © 2001-2007 Apache Software Foundation. All Rights Reserved.