com.plumtree.openfoundation.util
Class XPHashtable

java.lang.Object
  extended bycom.plumtree.openfoundation.util.XPHashtable
All Implemented Interfaces:
IXPDictionary
Direct Known Subclasses:
XPSynchronizedHashtable

public class XPHashtable
extends java.lang.Object
implements IXPDictionary

XPHashtable is a wrapper over HashMap and is not synchronized.

See Also:
XPSynchronizedHashTable, IXPDictionary

Field Summary
protected  java.util.HashMap hashMap
          The Hashmap used beneath XPHashtable.
static int KEYS
          The type argument to GetArray that denotes the key.
static int VALUES
          The type argument to GetArray() that denotes the value.
 
Constructor Summary
XPHashtable()
          Creates a new, empty XPHashtable.
XPHashtable(java.util.HashMap map)
          Construct an XPHashtable by wrapping the HashMap supplied.
XPHashtable(java.util.Hashtable _hashtable)
          Construct a new XPHashtable by copying the keys and values of the supplied Hashtable.
XPHashtable(int capacity)
          Creates a new, empty XPHashtable with the specified initial capacity.
XPHashtable(int capacity, float loadFactor)
          Creates a new, empty hashtable with the specified initial capacity and the specified load factor.
XPHashtable(XPHashtable hashtable)
          Copy constructor that clones the given XPHashtable.
 
Method Summary
 void Clear()
          Clears this hashtable so that it contains no keys.
 java.lang.Object Clone()
          Creates a shallow copy of this hashtable.
 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.
 boolean ContainsValue(java.lang.Object _value)
          Tests if this hashtable maps one or more keys to this value.
 java.lang.Object[] GetArray(int type)
          Returns an array of keys or values in the hashtable as indicated by the type argument.
 java.lang.Object GetElement(java.lang.Object key)
          Returns the value to which the specified key is mapped in this hashtable.
 IXPEnumerator GetElements()
          Returns an XPEnumerator that can iterate through the values in this hashtable.
 IXPDictionaryEnumerator GetEnumerator()
          Returns IXPDictionaryEnumerator for this dictionary.
 IXPEnumerator GetKeys()
          Returns an XPEnumerator that can iterate through the keys in this hashtable.
 int GetSize()
          Returns the number of elements in this hashtable.
static XPSynchronizedHashtable GetSynchronized(XPHashtable hashtable)
          Returns a sychronized wrapper of the give XPHashtable.
 java.util.HashMap GetUnderlyingObject()
          Returns the platfrom specific object that this class wraps.
 boolean IsEmpty()
          Tests if this hashtable has no elements.
 java.lang.Object PutElement(java.lang.Object key, java.lang.Object _value)
          Maps the specified key to the specified value in this hashtable.
 java.lang.Object RemoveElement(java.lang.Object key)
          Removes the key (and its corresponding value) from this hashtable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEYS

public static final int KEYS
The type argument to GetArray that denotes the key.

See Also:
Constant Field Values

VALUES

public static final int VALUES
The type argument to GetArray() that denotes the value.

See Also:
Constant Field Values

hashMap

protected java.util.HashMap hashMap
The Hashmap used beneath XPHashtable.

Constructor Detail

XPHashtable

public XPHashtable()
Creates a new, empty XPHashtable.


XPHashtable

public XPHashtable(java.util.HashMap map)
Construct an XPHashtable by wrapping the HashMap supplied.

Parameters:
map - HashMap supplied for the wrapper XPHashtable.

XPHashtable

public XPHashtable(java.util.Hashtable _hashtable)
Construct a new XPHashtable by copying the keys and values of the supplied Hashtable.

Parameters:
_hashtable - The Input Hashtable from which the XPHashtable is constructed.

XPHashtable

public XPHashtable(int capacity)
Creates a new, empty XPHashtable with the specified initial capacity.

Parameters:
capacity - the initial capacity of the list.

XPHashtable

public XPHashtable(int capacity,
                   float loadFactor)
Creates a new, empty hashtable with the specified initial capacity and the specified load factor.

Parameters:
capacity - the initial capactity of the hashtable.
loadFactor - the load factor of the hashtable.

XPHashtable

public XPHashtable(XPHashtable hashtable)
Copy constructor that clones the given XPHashtable.

Parameters:
hashtable - the Hashtable to be copied into this object
Method Detail

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 hashtable. All the structure of the hashtable itself is copied, but the keys and values are not cloned. This is a relatively expensive operation.

Returns:
a clone of the hashtable.

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.

ContainsKey

public boolean ContainsKey(java.lang.Object key)
Tests if the specified object is a key in this hashtable.

Specified by:
ContainsKey in interface IXPDictionary
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.

ContainsValue

public boolean ContainsValue(java.lang.Object _value)
Tests if this hashtable maps one or more keys to this value.

Parameters:
_value - value whose presence in this hashtable is to be tested.
Returns:
true if this hashtable maps one or more keys to the specified value.

GetArray

public java.lang.Object[] GetArray(int type)
Returns an array of keys or values in the hashtable as indicated by the type argument.

Parameters:
type - the type of information in the array returned (key or value)
Returns:
An array off keys or values in the hashtable as indicated by the type argument.

GetElement

public java.lang.Object GetElement(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable.

Specified by:
GetElement in interface IXPDictionary
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.

GetElements

public IXPEnumerator GetElements()
Returns an XPEnumerator that can iterate through the values in this hashtable.

Specified by:
GetElements in interface IXPDictionary
Returns:
An XPEnumerator that can iterate through the values in this hashtable.

GetKeys

public IXPEnumerator GetKeys()
Returns an XPEnumerator that can iterate through the keys in this hashtable.

Specified by:
GetKeys in interface IXPDictionary
Returns:
An XPEnumerator that can iterate through the keys in this hashtable.

GetEnumerator

public IXPDictionaryEnumerator GetEnumerator()
Returns IXPDictionaryEnumerator for this dictionary.

Specified by:
GetEnumerator in interface IXPDictionary
Returns:
IXPDictionaryEnumerator

GetSize

public int GetSize()
Returns the number of elements in this hashtable.

Specified by:
GetSize in interface IXPDictionary
Returns:
The number of elements in this hashtable.

IsEmpty

public boolean IsEmpty()
Tests if this hashtable has no elements.

Returns:
true if this hashtable has no elements; false otherwise.

PutElement

public java.lang.Object PutElement(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.

Specified by:
PutElement in interface IXPDictionary
Parameters:
key - the hashtable key.
_value - the value.
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one.

RemoveElement

public java.lang.Object RemoveElement(java.lang.Object key)
Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.

Specified by:
RemoveElement in interface IXPDictionary
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.

GetUnderlyingObject

public java.util.HashMap GetUnderlyingObject()
Returns the platfrom specific object that this class wraps.

Returns:
An instance of HashMap.

GetSynchronized

public static XPSynchronizedHashtable GetSynchronized(XPHashtable hashtable)
Returns a sychronized wrapper of the give XPHashtable.

Parameters:
hashtable - from which a Thread safe XPSynchronizedHashtable to be constructed.
Returns:
The Thread safe version of XPHashtable i.e., XPSynchronizedHashtable.


Copyright 2002, 2003, 2004 Plumtree Software Inc. All Rights Reserved.