com.sibvisions.util
Class KeyValueList<K,V>

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

public class KeyValueList<K,V>
extends Object

The KeyValueList mapps multiple values to a single key.


Constructor Summary
KeyValueList()
           
 
Method Summary
 void clear()
          Clears the list so that it contains no keys.
 boolean contains(K pKey, V pValue)
          Tests whether this list maps a key which contains a specific value.
 boolean containsKey(K pKey)
          Tests if the specified key is in this list.
 boolean containsValue(V pValue)
          Tests if the specified values is in this list.
 Enumeration<List<V>> elements()
          Returns an enumeration of the values in this list.
 Set<Map.Entry<K,List<V>>> entrySet()
          Returns a Set view of the entries contained in this list.
 boolean equals(Object pObject)
          
 List<V> get(K pKey)
          Returns the value list for the specified key in the list.
 int hashCode()
          
 boolean isEmpty()
          Tests if the list is empty.
 Set<K> keySet()
          Returns a Set view of the keys contained in this list.
 void put(K pKey, V pValue)
          Adds the specified pValue to a list of values which are mapped to the pKey.
 void put(K pKey, V pValue, boolean pUnique)
          Adds the specified pValue to a list of values which are mapped to the pKey.
 void putAll(K pKey, Collection<V> pValues)
          Adds the specified pValue collection to a list of values which are mapped to the pKey.
 List<V> remove(K pKey)
          Removes the key (and its corresponding value) from this list.
 void remove(K pKey, V pValue)
          Removes a specific pValue from a list of values which is mapped to the pKey.
 int size()
          Returns the number of keys.
 String toString()
          
 Collection<List<V>> values()
          Returns a collection of the values in this list.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeyValueList

public KeyValueList()
Method Detail

toString

public String toString()

Overrides:
toString in class Object

equals

public boolean equals(Object pObject)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

put

public void put(K pKey,
                V pValue)
Adds the specified pValue to a list of values which are mapped to the pKey. Neither the pKey nor the pValue can be null.

Parameters:
pKey - the key
pValue - the new value
Throws:
NullPointerException - if the key or value is null

putAll

public void putAll(K pKey,
                   Collection<V> pValues)
Adds the specified pValue collection to a list of values which are mapped to the pKey. Neither the pKey nor the pValue can be null.

Parameters:
pKey - the key
pValues - the new value collection
Throws:
NullPointerException - if the key or value is null

put

public void put(K pKey,
                V pValue,
                boolean pUnique)
Adds the specified pValue to a list of values which are mapped to the pKey. Neither the pKey nor the pValue can be null. It is possible to add the value only if it is not already added.

Parameters:
pKey - the key
pValue - the new value
pUnique - true to add the value only if it is not already in the list, false to add the value in any case
Throws:
NullPointerException - if the key or value is null

get

public List<V> get(K pKey)
Returns the value list for the specified key in the list.

Parameters:
pKey - the key
Returns:
the list of values that are mapped to the key or null if the key is unknown
Throws:
NullPointerException - if the key is null

remove

public void remove(K pKey,
                   V pValue)
Removes a specific pValue from a list of values which is mapped to the pKey.

Parameters:
pKey - the key
pValue - the value to be removed

clear

public void clear()
Clears the list so that it contains no keys.


remove

public List<V> remove(K pKey)
Removes the key (and its corresponding value) from this list. This method does nothing if the key is not in the list.

Parameters:
pKey - the key that needs to be removed.
Returns:
the list of values to which the key had been mapped, or null if the key did not have a values.
Throws:
NullPointerException - if the key is null.

containsKey

public boolean containsKey(K pKey)
Tests if the specified key is in this list.

Parameters:
pKey - possible key.
Returns:
true if and only if the specified key is in this list, false otherwise.
Throws:
NullPointerException - if the key is null.

containsValue

public boolean containsValue(V pValue)
Tests if the specified values is in this list.

Parameters:
pValue - possible value.
Returns:
true if and only if the specified value is in this list, false otherwise.

contains

public boolean contains(K pKey,
                        V pValue)
Tests whether this list maps a key which contains a specific value.

Parameters:
pKey - the key.
pValue - the value.
Returns:
true when the value is mapped with the given key, otherwise false.

size

public int size()
Returns the number of keys.

Returns:
the number of keys.

isEmpty

public boolean isEmpty()
Tests if the list is empty.

Returns:
true if the list is empty, false otherwise.

elements

public Enumeration<List<V>> elements()
Returns an enumeration of the values in this list. Use the Enumeration methods on the returned object to fetch the elements sequentially.

Returns:
an enumeration of the values in this list.
See Also:
Enumeration

values

public Collection<List<V>> values()
Returns a collection of the values in this list.

Returns:
a collection of the values in this list.
See Also:
Collection

keySet

public Set<K> keySet()
Returns a Set view of the keys contained in this list. The Set is backed by the list, so changes to the list are reflected in the Set, and vice-versa. The Set supports element removal (which removes the corresponding entry from the list), but not element addition.

Returns:
a set view of the keys contained in this list.

entrySet

public Set<Map.Entry<K,List<V>>> entrySet()
Returns a Set view of the entries contained in this list. Each element in this collection is a Map.Entry. The Set is backed by the list, so changes to the list are reflected in the Set, and vice-versa. The Set supports element removal (which removes the corresponding entry from the list), but not element addition.

Returns:
a set view of the mappings contained in this list.
See Also:
Map.Entry


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.