Nitido Inc.

com.nitido.util
Class OpenHash

java.lang.Object
  extended by com.nitido.util.OpenHash
All Implemented Interfaces:
java.io.Serializable

public class OpenHash
extends java.lang.Object
implements java.io.Serializable

A Hashtable that allows more than one value associated to the same key.

See Also:
Serialized Form

Constructor Summary
OpenHash()
          Constructs a new, empty OpenHash.
OpenHash(java.util.Hashtable hash)
          Constructs a new OpenHash, copying the contents of the passed in Hashtable object into the OpenHash.
OpenHash(OpenHash hash)
          Copy constructor.
 
Method Summary
 void clear()
          This method removes all entries from the hashtable.
 boolean containsKey(java.lang.Object key)
          Returns true if this OpenHash contains a key equal to the one passed in.
 boolean containsValue(java.lang.Object value)
          Returns true if this OpenHash contains the given value.
 boolean containsValue(java.lang.Object key, java.lang.Object value)
          Returns true if this OpenHash contains the given value with the given key.
 java.lang.Object get(java.lang.Object key)
          This method retrieves the first value which corresponds to the key given, or null if no value is mapped to that key.
 java.lang.Object get(java.lang.Object key, int index)
          This method retrieves the specified value which corresponds to the key given and the specified index, or null if no value is mapped to that key.
 java.util.Enumeration getKeys()
          Returns an Enumeration of all of the keys in this OpenHash.
 int getNumberOfValues(java.lang.Object key)
          Returns number of value object stored under the specified key.
 java.lang.Object getValue(java.lang.Object key, int index)
          Return the value specified by the index.
 java.util.Enumeration getValues(java.lang.Object key)
          Returns an enumeration of values for the given key.
 java.util.Vector getValuesVector(java.lang.Object key)
          Returns a vector of all the values associated to the given key.
 java.util.Enumeration keys()
          Convenience alias to getKeys() for Hashtable users.
 void put(java.lang.Object key, java.lang.Object value)
          This method add a value to be associated to a key in the hashtable.
 void putAll(java.lang.Object key, java.util.Collection values)
          This method add the specified values to be all associated to a key in the hashtable.
 void putValues(java.lang.Object key, java.util.Collection values)
          This method maps a key to a value in the hashtable.
 java.util.Vector remove(java.lang.Object key)
          Removes all the values that are associated with the given key.
 java.lang.Object remove(java.lang.Object key, int index)
          Remove the specified value associated to the key.
 java.lang.Object remove(java.lang.Object key, java.lang.Object value)
          Removes the key/value pair specified.
 void set(java.lang.Object key, int index, java.lang.Object value)
          This method replace the specified value with the new value.
 void set(java.lang.Object key, java.lang.Object value)
          This method maps a key to a value in the hashtable and replace the all old mapped values if they exist.
 void setValues(java.lang.Object key, java.util.Collection values)
          This method replace all old mapped values with the new ones.
 int size()
          Returns the number of keys in this OpenHash.
 java.lang.String toString()
          Utility methods to list all the entries in the hashtable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OpenHash

public OpenHash()
Constructs a new, empty OpenHash.


OpenHash

public OpenHash(java.util.Hashtable hash)
Constructs a new OpenHash, copying the contents of the passed in Hashtable object into the OpenHash.

Parameters:
hash - The Hashtable whose contents are copied into this OpenHash.

OpenHash

public OpenHash(OpenHash hash)
Copy constructor.

Method Detail

get

public java.lang.Object get(java.lang.Object key)
This method retrieves the first value which corresponds to the key given, or null if no value is mapped to that key.

Parameters:
key - A key in the hashtable.
Returns:
The first mapping or null if there is none.

get

public java.lang.Object get(java.lang.Object key,
                            int index)
This method retrieves the specified value which corresponds to the key given and the specified index, or null if no value is mapped to that key.

Parameters:
key - A key in the hashtable.
Returns:
The first mapping or null if there is none.

getKeys

public java.util.Enumeration getKeys()
Returns an Enumeration of all of the keys in this OpenHash.

Returns:
Returns an Enumeration of all of the keys in this OpenHash.

keys

public java.util.Enumeration keys()
Convenience alias to getKeys() for Hashtable users.


getNumberOfValues

public int getNumberOfValues(java.lang.Object key)
Returns number of value object stored under the specified key.

Parameters:
key - The key object to retrieve the value count from.
Returns:
The count of the values stored under the key.

getValues

public java.util.Enumeration getValues(java.lang.Object key)
Returns an enumeration of values for the given key.

Parameters:
key - A key in the hashtable.
Returns:
An enumeration of the values for the key.

getValuesVector

public java.util.Vector getValuesVector(java.lang.Object key)
Returns a vector of all the values associated to the given key.

Parameters:
key - A key in the hashtable.
Returns:
A vector of the values associated too the key

getValue

public java.lang.Object getValue(java.lang.Object key,
                                 int index)
Return the value specified by the index.

Parameters:
key - A key in the hashtable.
index - The index of the value to be fetched.
Returns:
The specified value.

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this OpenHash contains the given value.

Parameters:
value - The value to check for in this OpenHash.
Returns:
True if the value is found in the OpenHash, otherwise false.

containsValue

public boolean containsValue(java.lang.Object key,
                             java.lang.Object value)
Returns true if this OpenHash contains the given value with the given key.

Parameters:
key - The key to search for in this OpenHash.
value - The value to search for in this OpenHash.
Returns:
Returns true if the key/value pair is found, otherwise returns false.

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this OpenHash contains a key equal to the one passed in.

Parameters:
key - The key to check.
Returns:
True if the key is found, false otherwise.

size

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

Returns:
The number of keys in this OpenHash.

put

public void put(java.lang.Object key,
                java.lang.Object value)
This method add a value to be associated to a key in the hashtable.

Parameters:
key - The object to be used as a key in the mapping.
value - The object which the key is being mapped to.

putAll

public void putAll(java.lang.Object key,
                   java.util.Collection values)
This method add the specified values to be all associated to a key in the hashtable.

Parameters:
key - The object to be used as a key in the mapping.
values - The object which the key is being mapped to.

putValues

public void putValues(java.lang.Object key,
                      java.util.Collection values)
This method maps a key to a value in the hashtable. It will add the new values to the existing values associated to the key.

Parameters:
key - The object to be used as a key in the mapping.
values - The collection of the values associated to the key.

set

public void set(java.lang.Object key,
                java.lang.Object value)
This method maps a key to a value in the hashtable and replace the all old mapped values if they exist.

Parameters:
key - The object to be used as a key in the mapping.
value - The object which the key is being mapped to.

setValues

public void setValues(java.lang.Object key,
                      java.util.Collection values)
This method replace all old mapped values with the new ones.

Parameters:
key - The object to be used as a key in the mapping.
values - The collection of values to be associated to the key.

set

public void set(java.lang.Object key,
                int index,
                java.lang.Object value)
This method replace the specified value with the new value. It will only replace the value pointed by the index, and all other values remains unchanged.

Parameters:
key - The object to be used as a key in the mapping.
index - The index of the value to be replaced.
value - The object which the key is being mapped to.

remove

public java.util.Vector remove(java.lang.Object key)
Removes all the values that are associated with the given key.

Parameters:
key - the key to be removed.
Returns:
A Vector containing the objects removed from this OpenHash, or null if there was no such key.

remove

public java.lang.Object remove(java.lang.Object key,
                               java.lang.Object value)
Removes the key/value pair specified.

Parameters:
key - The key in the key/value pair to remove.
value - The value in the key/value pair to remove.
Returns:
The element removed, or null if no matching key/value pair was found.

remove

public java.lang.Object remove(java.lang.Object key,
                               int index)
Remove the specified value associated to the key. If the specified index doesn't exists, this method will not change anything under the key and return a null object. If there exists a value under the specified key and index, that value will be removed from the hash and returned by this method.

Parameters:
key - The key in the key/value pair to be removed.
index - The index of the value to be removed.

clear

public void clear()
This method removes all entries from the hashtable.


toString

public java.lang.String toString()
Utility methods to list all the entries in the hashtable. The format will be
 keyA: "valueA-1", "valueA-2", ...
 keyB: "valueB-1", "valueB-2", ...
 

Overrides:
toString in class java.lang.Object

Nitido NiM 2.5 Java API

These JavaDoc pages are generated for release/nim_2_5-2.5.44

Copyright © 1999-2009 Nitido Inc.    Proprietary and Confidential.    All Rights Reserved.