ariba.util.core
Class GrowOnlyHashtable<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by ariba.util.core.GrowOnlyHashtable<K,V>
All Implemented Interfaces:
Map<K,V>
Direct Known Subclasses:
BigDecimalMoneyFormatter.CurrencyFormatterMap, GrowOnlyHashtable.IdentityMap, InternCharToString

public class GrowOnlyHashtable<K,V>
extends AbstractMap<K,V>

A version of Hashtable that... - Is built on the code base of the ariba.util.core.Hashtable - Only has methods for querying and putting elements. There is no ability to remove an element. - Has synchronization built in to allow the following: 1) No synchronization is necessary (either internally or externally) on get() operations 2) The put() method is internally synchronized on the this ref. If the program is not concerned about which object ends up in the table after two concurrent puts, no additional synchronization is needed. But if a program desires to ensure that only one is entered, external synchronization can be done on the object to allow synchronization between a retry of a failed get and a put. See the ariba.util.core.InternCharToString for an example of this. -- I believe that a clear() method could also be added without requiring synchronization, however I do not have the time to validate this.


Nested Class Summary
static class GrowOnlyHashtable.IdentityMap
           
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static String ClassName
           
 
Constructor Summary
GrowOnlyHashtable()
          Constructs an empty Hashtable.
GrowOnlyHashtable(int initialCapacity)
          Constructs a Hashtable capable of holding at least initialCapacity elements before needing to grow.
 
Method Summary
 int capacity()
          Returns the current capacity of the GrowOnlyHashtable.
 boolean contains(V element)
          Returns true if the GrowOnlyHashtable contains the element.
 boolean containsKey(Object key)
          Returns true if the GrowOnlyHashtable contains the key key.
 int count()
          Returns the number of elements in the GrowOnlyHashtable.
 V[] elementsArray()
          Returns an Object array containing the Hashtable's elements.
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
          Returns the element associated with the key.
 boolean isEmpty()
          Returns true if there are no elements in the GrowOnlyHashtable.
 K[] keysArray()
          Returns an Object array containing the Hashtable's keys.
 List<K> keysList()
          Returns a List containing the Hashtable's keys.
 V put(K key, V element)
          Places the key/element pair in the GrowOnlyHashtable.
 int size()
          Returns the number of elements in the GrowOnlyHashtable.
 String toString()
           
 
Methods inherited from class java.util.AbstractMap
clear, containsValue, equals, hashCode, keySet, putAll, remove, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ClassName

public static final String ClassName
See Also:
Constant Field Values
Constructor Detail

GrowOnlyHashtable

public GrowOnlyHashtable()
Constructs an empty Hashtable. The Hashtable will grow on demand as more elements are added.


GrowOnlyHashtable

public GrowOnlyHashtable(int initialCapacity)
Constructs a Hashtable capable of holding at least initialCapacity elements before needing to grow.

Method Detail

count

public int count()
Returns the number of elements in the GrowOnlyHashtable.


size

public int size()
Returns the number of elements in the GrowOnlyHashtable.

Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>

capacity

public int capacity()
Returns the current capacity of the GrowOnlyHashtable.


isEmpty

public boolean isEmpty()
Returns true if there are no elements in the GrowOnlyHashtable.

Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class AbstractMap<K,V>

keysArray

public K[] keysArray()
Returns an Object array containing the Hashtable's keys. If the Hashtable contains no keys, an empty array is returned.

Returns:
the Object array above mentioned.

elementsArray

public V[] elementsArray()
Returns an Object array containing the Hashtable's elements. If there the hashtable contains no elements, an empty array is returned.

Returns:
the Object array mentioned above.

contains

public boolean contains(V element)
Returns true if the GrowOnlyHashtable contains the element. This method is slow -- O(n) -- because it must scan the table searching for the element.


containsKey

public boolean containsKey(Object key)
Returns true if the GrowOnlyHashtable contains the key key.

Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

get

public V get(Object key)
Returns the element associated with the key. This method returns null if the GrowOnlyHashtable does not contain key. GrowOnlyHashtable hashes and compares key using hashCode() and equals().

Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

put

public V put(K key,
             V element)
Places the key/element pair in the GrowOnlyHashtable. Neither key nor element may be null. Returns the old element associated with key, or null if the key was not present.

Specified by:
put in interface Map<K,V>
Overrides:
put in class AbstractMap<K,V>

keysList

public List<K> keysList()
Returns a List containing the Hashtable's keys.


toString

public String toString()
Overrides:
toString in class AbstractMap<K,V>

entrySet

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


AribaWeb User Interface Development Framework
Copyright © 2000-2009 Ariba, Inc. All Rights Reserved.