torero.util
Class OneToManyMap

java.lang.Object
  |
  +--torero.util.OneToManyMap
All Implemented Interfaces:
Serializable

public class OneToManyMap
extends Object
implements Serializable

A collection class for mapping one key to many values. In difference to the Hashmap this collection allows to associate more than one value to a certain key. Therefore binnings can be implemented with this collection type. Note that this implementation is not synchronized. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. The OneToManyMap also supports serialisation. Looking up the values associated to a key is done with hashing.

See Also:
Serialized Form

Constructor Summary
OneToManyMap(int size)
          The constuctor argument is used to set the initial capacity of key values.
 
Method Summary
 void clear()
          Removes all keys and their associated values from this OneToManyMap.
 ListIterator get(Object key)
          Returns an iterator of Objects associated to the given key.
 Iterator getAllValues()
          Returns an iterator of all values of this OneToManyMap.
 Iterator getKeys()
          Returns an iterator of all keys of this OneToManyMap.
 boolean put(Object key, Object value)
          Adds the given value to the given key and returns false if the value is already associated to the given key.
 boolean removeKey(Object key)
          Remove the given key and all its values from this OneToManyMap.
 boolean removeValue(Object key, Object value)
          Remove the given value from the given key in this OneToManyMap.
 int size()
          Returns the number of keys this OneToManyMap has.
 String toString()
          Returns a String representation of this OneToManyMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OneToManyMap

public OneToManyMap(int size)
The constuctor argument is used to set the initial capacity of key values. (This preallocates memory needed for mainining the given number of keys)
Parameters:
size - takes the number of key elements initally used.
Method Detail

get

public ListIterator get(Object key)
Returns an iterator of Objects associated to the given key.
Parameters:
key - takes the key object.
Returns:
returns an iterator of Objects associated to the given key. If no values with that key can be found null is returned.

getKeys

public Iterator getKeys()
Returns an iterator of all keys of this OneToManyMap.
Returns:
returns an iterator of all keys of this OneToManyMap.

getAllValues

public Iterator getAllValues()
Returns an iterator of all values of this OneToManyMap.
Returns:
returns an iterator of all values of this OneToManyMap.

put

public boolean put(Object key,
                   Object value)
Adds the given value to the given key and returns false if the value is already associated to the given key.
Parameters:
key - takes the key the value should be added to
value - takes the value that should be added
Returns:
false if the value is already associated to the given key

removeKey

public boolean removeKey(Object key)
Remove the given key and all its values from this OneToManyMap.
Parameters:
key - takes the key the value should be added to
Returns:
false if this OneToManyMap does not contain the given key

removeValue

public boolean removeValue(Object key,
                           Object value)
Remove the given value from the given key in this OneToManyMap.
Parameters:
key - takes the key from where the given value should be removed
value - takes the value to remove from the given key
Returns:
false if this OneToManyMap does not contain the given value for the given key

clear

public void clear()
Removes all keys and their associated values from this OneToManyMap.

size

public int size()
Returns the number of keys this OneToManyMap has.
Returns:
returns the number of keys this OneToManyMap has

toString

public String toString()
Returns a String representation of this OneToManyMap.
Overrides:
toString in class Object
Returns:
returns a String representation of this OneToManyMap