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:
java.util.Map<K,V>
Direct Known Subclasses:
BigDecimalMoneyFormatter.CurrencyFormatterMap, GrowOnlyHashtable.IdentityMap, InternCharToString

public class GrowOnlyHashtable<K,V>
extends java.util.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<K,V>
           
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
static java.lang.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(java.lang.Object key)
          Returns true if the GrowOnlyHashtable contains the key key.
 int count()
          Returns the number of elements in the GrowOnlyHashtable.
 java.lang.Object[] elementsArray()
          Returns an Object array containing the Hashtable's elements.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 V get(java.lang.Object key)
          Returns the element associated with the key.
 boolean isEmpty()
          Returns true if there are no elements in the GrowOnlyHashtable.
 java.lang.Object[] keysArray()
          Returns an Object array containing the Hashtable's keys.
 java.util.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.
 java.lang.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 java.lang.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 java.util.Map<K,V>
Overrides:
size in class java.util.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 java.util.Map<K,V>
Overrides:
isEmpty in class java.util.AbstractMap<K,V>

keysArray

public java.lang.Object[] 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 java.lang.Object[] 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(java.lang.Object key)
Returns true if the GrowOnlyHashtable contains the key key.

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

get

public V get(java.lang.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 java.util.Map<K,V>
Overrides:
get in class java.util.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 java.util.Map<K,V>
Overrides:
put in class java.util.AbstractMap<K,V>

keysList

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


toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractMap<K,V>

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>
See Also:
Map.entrySet()


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