com.sibvisions.util
Class GroupHashtable<G,K,V>

java.lang.Object
  extended by com.sibvisions.util.GroupHashtable<G,K,V>
Type Parameters:
G - group class
K - key class
V - value class

public class GroupHashtable<G,K,V>
extends Object

The GroupHashtable is a utility class to group multiple key/value pairs with a single group key.
Its implementation has a Hashtable, for the group, which contains multiple Hashtables, for the key/value pairs.


Constructor Summary
GroupHashtable()
           
 
Method Summary
 void clear()
          Clears all entries.
 void clear(G pGroup)
          Clears all entries from a specific group.
 boolean constainsKey(G pGroup, K pKey)
          Tests if the specified object is a key in the group mapping.
 boolean containsValue(G pGroup, V pValue)
          Returns true if the group maps one or more keys to this value.
 Enumeration<V> elements(G pGroup)
          Returns an enumeration of the values associated with a group, in this hashtable.
 Hashtable<K,V> get(G pGroup)
          Returns the internal Hashtable associated with the pGroup.
 V get(G pGroup, K pKey)
          Returns the value to which the specified key is mapped.
 Enumeration<K> keys(G pGroup)
          Returns an enumeration of the keys associated with a group, in this hashtable.
 void put(G pGroup, K pKey, V pValue)
          Associates the specified value with the specified key to the group.
 boolean remove(G pGroup)
          Removes the mapping of an entire group if it is present.
 V remove(G pGroup, K pKey)
          Removes the mapping for a key from its group if it is present.
 int size()
          Returns the group count.
 int size(G pGroup)
          Returns the number of group elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupHashtable

public GroupHashtable()
Method Detail

put

public void put(G pGroup,
                K pKey,
                V pValue)
Associates the specified value with the specified key to the group.

Parameters:
pGroup - group identifier
pKey - key with which the specified value is to be associated
pValue - value to be associated with the specified key

get

public V get(G pGroup,
             K pKey)
Returns the value to which the specified key is mapped.

Parameters:
pGroup - group identifier
pKey - the key whose associated value is to be returned
Returns:
the value to which the specified key is mapped or null if the key or the group is not mapped.

get

public Hashtable<K,V> get(G pGroup)
Returns the internal Hashtable associated with the pGroup.

Parameters:
pGroup - group identifier
Returns:
the Hashtable which is mapped to the specified group or null if the pGroup is not mapped

remove

public boolean remove(G pGroup)
Removes the mapping of an entire group if it is present.

Parameters:
pGroup - group identifier
Returns:
true if the group was removed, false if the group is not present or can not be removed

remove

public V remove(G pGroup,
                K pKey)
Removes the mapping for a key from its group if it is present.

Parameters:
pGroup - group identifier
pKey - key to remove
Returns:
the previous value associated with the key or null if there is no mapping the key

size

public int size()
Returns the group count.

Returns:
number of groups

size

public int size(G pGroup)
Returns the number of group elements.

Parameters:
pGroup - group identifier
Returns:
number of group elements

elements

public Enumeration<V> elements(G pGroup)
Returns an enumeration of the values associated with a group, in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.

Parameters:
pGroup - group identifier
Returns:
an enumeration of the values in this hashtable

keys

public Enumeration<K> keys(G pGroup)
Returns an enumeration of the keys associated with a group, in this hashtable.

Parameters:
pGroup - group identifier
Returns:
enumeration of the keys in this hashtable

containsValue

public boolean containsValue(G pGroup,
                             V pValue)
Returns true if the group maps one or more keys to this value.

Parameters:
pGroup - group identifier
pValue - value whose presence is to be tested
Returns:
true if the group maps one or more keys to the specified value, false otherwise

constainsKey

public boolean constainsKey(G pGroup,
                            K pKey)
Tests if the specified object is a key in the group mapping.

Parameters:
pGroup - group identifier
pKey - possible key
Returns:
true if and only if the specified key is mapped in the group, false otherwise

clear

public void clear()
Clears all entries.


clear

public void clear(G pGroup)
Clears all entries from a specific group.

Parameters:
pGroup - the group identifier


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.