com.groiss.ds
Class MultiMap

java.lang.Object
  extended by com.groiss.ds.MultiMap
All Implemented Interfaces:
java.io.Serializable

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

A MultiMap maps keys to objects, where one key can be mapped to a set of objects.

See Also:
Serialized Form

Constructor Summary
MultiMap()
          Constructs a MultiMap.
MultiMap(int initialSubSize)
          Constructs a MultiMap and specifies an initial size for the Vectors holding the values to the keys.
MultiMap(int capacity, int initialSubSize)
          Creates a new MultiMap with the defined capacity and Vector size.
 
Method Summary
 boolean containsKey(java.lang.Object key)
          Use this method to find out if the given key exists in this MultiMap.
 int count(java.lang.Object key)
          Returns number of values mapped to a given key.
 java.util.Enumeration elements()
          Returns the elements in the map
 java.util.Enumeration get(java.lang.Object key)
          Returns all values mapped to a given key.
 java.util.Vector getEntries(java.lang.Object key)
          Returns all values mapped to a given key.
 boolean hasValue(java.lang.Object key, java.lang.Object value)
          Finds out if the object key has a mapping to the object value.
 boolean isEmpty()
          Is the map emtpy?
 java.util.Enumeration keys()
          Return the keys
 java.util.Set keySet()
          Return the keys
 void put(java.lang.Object key, java.lang.Object value)
          Put the mapping of a key and an object to the map.
 void putAll(java.lang.Object key, java.util.List values)
          Put the mapping of a key to a list of values to the map.
 void remove(java.lang.Object key)
          Removes a key from the map.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiMap

public MultiMap()
Constructs a MultiMap.


MultiMap

public MultiMap(int initialSubSize)
Constructs a MultiMap and specifies an initial size for the Vectors holding the values to the keys. Every new Vector will be created with this initial size. If you use the other constructor, the initial size will have a default value of 16.

Parameters:
initialSubSize - New Vectors will be created with this size.

MultiMap

public MultiMap(int capacity,
                int initialSubSize)
Creates a new MultiMap with the defined capacity and Vector size.

Parameters:
capacity - The Map will have this initial size. The load factor is the standard value of 0.75.
initialSubSize - New Vectors will be created with this size.
Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object value)
Put the mapping of a key and an object to the map.

Parameters:
key - a key
value - the value object.

putAll

public void putAll(java.lang.Object key,
                   java.util.List values)
Put the mapping of a key to a list of values to the map.

Parameters:
key - a key
values - the values fo the key

get

public java.util.Enumeration get(java.lang.Object key)
Returns all values mapped to a given key.

Parameters:
key - the key object
Returns:
the values enumeration

hasValue

public boolean hasValue(java.lang.Object key,
                        java.lang.Object value)
Finds out if the object key has a mapping to the object value.

Parameters:
key - The key object.
value - The desired value object.
Returns:
true if the key object contains a mapping to the given value object. In all other cases (also if the key doesn't exist at all), false will be returned.

containsKey

public boolean containsKey(java.lang.Object key)
Use this method to find out if the given key exists in this MultiMap.

Parameters:
key - The key object.
Returns:
true if the key exists, else false will be returned.

count

public int count(java.lang.Object key)
Returns number of values mapped to a given key.

Parameters:
key - the key object
Returns:
the number of objects stored with this key.

getEntries

public java.util.Vector getEntries(java.lang.Object key)
Returns all values mapped to a given key.

Parameters:
key - the key object
Returns:
the values

remove

public void remove(java.lang.Object key)
Removes a key from the map.

Parameters:
key - the key object

elements

public java.util.Enumeration elements()
Returns the elements in the map

Returns:
an enumeration containung vectors of elements mapped to the keys

keys

public java.util.Enumeration keys()
Return the keys

Returns:
an Enumeration containing the keys.

keySet

public java.util.Set keySet()
Return the keys

Returns:
a Set containing the keys.

isEmpty

public boolean isEmpty()
Is the map emtpy?

Returns:
true, if empty.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2001-2006 Groiss Informatics GmbH. All Rights Reserved.