net.innig.collect
Class CompositeMultiMap<K,V>

java.lang.Object
  extended by net.innig.collect.CompositeMultiMap<K,V>
All Implemented Interfaces:
java.io.Serializable, MultiMap<K,V>
Direct Known Subclasses:
HashMultiMap, TreeMultiMap

public class CompositeMultiMap<K,V>
extends java.lang.Object
implements MultiMap<K,V>, java.io.Serializable

A multi-map implementation which combines existing Map and Set implementations.

Maturity: This is a 90% mature API, and a stable implementation. It performs well in formal testing, but has not undergone real-world testing.
Plans: There are no current plans to expand or revise this class's functionality.

See Also:
Serialized Form

Nested Class Summary
 class CompositeMultiMap.Entry<EK,EV>
           
 
Constructor Summary
CompositeMultiMap(java.lang.Class<? extends java.util.Map> mapClass, java.lang.Class<? extends java.util.Set> setClass)
          Creates a new empty composite multi-map.
CompositeMultiMap(java.lang.Class<? extends java.util.Map> mapClass, java.lang.Class<? extends java.util.Set> setClass, java.util.Map<? extends K,? extends V> map)
          Creates a new composite multi-map which is a shallow copy of an existing map.
CompositeMultiMap(java.lang.Class<? extends java.util.Map> mapClass, java.lang.Class<? extends java.util.Set> setClass, MultiMap<? extends K,? extends V> multimap)
          Creates a new composite multi-map which is a shallow copy of an existing multi-map.
CompositeMultiMap(java.util.Map<K,java.util.Set<V>> map, java.lang.Class<? extends java.util.Set> setClass)
           
CompositeMultiMap(java.util.TreeMap<K,java.util.Set<V>> map, Factory<java.util.Set<V>> setFactory)
           
 
Method Summary
 void clear()
          Clears all entries.
 boolean containsKey(K key)
          Returns true if there is at least one mapping for the given key.
 boolean containsValue(V searchValue)
          Returns true if there is at least one key which maps to the given values.
 java.util.Set<MultiMap.Entry<K,V>> entrySet()
          Returns the set of key/value pairs in this multi-map.
 boolean equals(java.lang.Object other)
          Two multi-maps are equal iff they contain the same key/value mappings.
 java.util.Set<V> get(K key)
          Returns the set of values for a given key.
 int hashCode()
           
 boolean isEmpty()
          Returns true if there are no mappings.
 java.util.Set<K> keySet()
          Returns the set of keys in this multi-map.
 boolean put(K key, V value)
          Adds a mapping from a key to a value.
 boolean putAll(K key, java.util.Collection<? extends V> values)
          Adds mappings from a key to several different values.
 void putAll(java.util.Map<? extends K,? extends V> map)
          Adds all entries from a map to this multi-map.
 void putAll(MultiMap<? extends K,? extends V> multimap)
          Adds all entries from another multi-map to this one.
 boolean remove(K key, V value)
          Removes a key/value mapping.
 java.util.Set<V> removeKey(K key)
          Removes all key/value mappings for a given key.
 int size()
          Returns the number of key/value mappings in the multi-map.
 java.lang.String toString()
           
 java.util.Collection<V> values()
          Returns the values in this multi-map.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompositeMultiMap

public CompositeMultiMap(java.lang.Class<? extends java.util.Map> mapClass,
                         java.lang.Class<? extends java.util.Set> setClass)
Creates a new empty composite multi-map.

Parameters:
mapClass - A class implementing Map with a no-args constructor.
setClass - A class implementing Set with a no-args constructor.

CompositeMultiMap

public CompositeMultiMap(java.lang.Class<? extends java.util.Map> mapClass,
                         java.lang.Class<? extends java.util.Set> setClass,
                         MultiMap<? extends K,? extends V> multimap)
Creates a new composite multi-map which is a shallow copy of an existing multi-map.

Parameters:
mapClass - A class implementing Map with a no-args constructor.
setClass - A class implementing Set with a no-args constructor.
multimap - The intial key/value mappings for this multimap.

CompositeMultiMap

public CompositeMultiMap(java.lang.Class<? extends java.util.Map> mapClass,
                         java.lang.Class<? extends java.util.Set> setClass,
                         java.util.Map<? extends K,? extends V> map)
Creates a new composite multi-map which is a shallow copy of an existing map.

Parameters:
mapClass - A class implementing Map with a no-args constructor.
setClass - A class implementing Set with a no-args constructor.
map - The intial key/value mappings for this multimap.

CompositeMultiMap

public CompositeMultiMap(java.util.Map<K,java.util.Set<V>> map,
                         java.lang.Class<? extends java.util.Set> setClass)

CompositeMultiMap

public CompositeMultiMap(java.util.TreeMap<K,java.util.Set<V>> map,
                         Factory<java.util.Set<V>> setFactory)
Method Detail

size

public int size()
Description copied from interface: MultiMap
Returns the number of key/value mappings in the multi-map.

Specified by:
size in interface MultiMap<K,V>

isEmpty

public boolean isEmpty()
Description copied from interface: MultiMap
Returns true if there are no mappings.

Specified by:
isEmpty in interface MultiMap<K,V>

containsKey

public boolean containsKey(K key)
Description copied from interface: MultiMap
Returns true if there is at least one mapping for the given key.

Specified by:
containsKey in interface MultiMap<K,V>

containsValue

public boolean containsValue(V searchValue)
Description copied from interface: MultiMap
Returns true if there is at least one key which maps to the given values. Note that this method will likely execute in linear time in the number of key/value paris.

Specified by:
containsValue in interface MultiMap<K,V>

get

public java.util.Set<V> get(K key)
Description copied from interface: MultiMap
Returns the set of values for a given key.

Specified by:
get in interface MultiMap<K,V>

put

public boolean put(K key,
                   V value)
Description copied from interface: MultiMap
Adds a mapping from a key to a value. This does not replace other existing mappings from the same key. However, if the key/value pair is already in the multi-map, it will not be added twice.

Specified by:
put in interface MultiMap<K,V>
Returns:
true if the new key/value pair was not already in the multi-map.

putAll

public boolean putAll(K key,
                      java.util.Collection<? extends V> values)
Description copied from interface: MultiMap
Adds mappings from a key to several different values. These values are in addition to any existing mappings for the given key.

Specified by:
putAll in interface MultiMap<K,V>
Returns:
true if any of the new key/value pairs were not already in the multi-map.

remove

public boolean remove(K key,
                      V value)
Description copied from interface: MultiMap
Removes a key/value mapping.

Specified by:
remove in interface MultiMap<K,V>
Returns:
true if the key/value pair was in the multi-map.

removeKey

public java.util.Set<V> removeKey(K key)
Description copied from interface: MultiMap
Removes all key/value mappings for a given key.

Specified by:
removeKey in interface MultiMap<K,V>
Returns:
The set of values which were associated with removed key.

putAll

public void putAll(MultiMap<? extends K,? extends V> multimap)
Description copied from interface: MultiMap
Adds all entries from another multi-map to this one.

Specified by:
putAll in interface MultiMap<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> map)
Description copied from interface: MultiMap
Adds all entries from a map to this multi-map.

Specified by:
putAll in interface MultiMap<K,V>

clear

public void clear()
Description copied from interface: MultiMap
Clears all entries.

Specified by:
clear in interface MultiMap<K,V>

keySet

public java.util.Set<K> keySet()
Description copied from interface: MultiMap
Returns the set of keys in this multi-map. The returned set is backed by the actual multi-map, and will reflect subsequent changes.

Specified by:
keySet in interface MultiMap<K,V>

values

public java.util.Collection<V> values()
Description copied from interface: MultiMap
Returns the values in this multi-map. The returned collection is backed by the actual multi-map, and will reflect subsequent changes.

Specified by:
values in interface MultiMap<K,V>

entrySet

public java.util.Set<MultiMap.Entry<K,V>> entrySet()
Description copied from interface: MultiMap
Returns the set of key/value pairs in this multi-map. The returned set is backed by the actual multi-map, and will reflect subsequent changes.

Specified by:
entrySet in interface MultiMap<K,V>

equals

public boolean equals(java.lang.Object other)
Description copied from interface: MultiMap
Two multi-maps are equal iff they contain the same key/value mappings.

Specified by:
equals in interface MultiMap<K,V>
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface MultiMap<K,V>
Overrides:
hashCode in class java.lang.Object

toString

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