Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.7.2)

E13403-10


oracle.javatools.util
Class MultiMap<K,V>

java.lang.Object
  extended by oracle.javatools.util.MultiMap<K,V>

All Implemented Interfaces:
java.util.Map<K,java.util.Collection<V>>

public class MultiMap<K,V>
extends java.lang.Object
implements java.util.Map<K,java.util.Collection<V>>

An object that maps keys to collections of values. MultiMap<K,V> is, in fact, a subtype of Map<K,Collection<V>>; this type adds a small number of methods that accept values of V directly, rather than values of Collection<V>.

MultiMap uses an underlying map to store the keys and associated collections, and uses reflection to create the collections when needed. From the default constructor, the underlying map is a LinkedHashMap, and the collections class is ArrayList; other constructors allow other classes to be specified (for example, ArraySortedSet for the collections class).

If the collection of values associated with a key becomes empty for any reason, the collection is removed from the map. This ensures, for example, that isEmpty() == (valuesSize() == 0) and that containsKey(key) == (valuesSize(key) > 0).


Nested Class Summary

 

Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>

 

Constructor Summary
MultiMap()
          Creates a new MultiMap based on a map of type LinkedHashMap and collections of type ArrayList.
MultiMap(java.lang.Class<? extends java.util.Collection> collectionClass)
          Creates a new MultiMap based on a map of type LinkedHashMap and collections of a specified type.
MultiMap(java.lang.Class<? extends java.util.Map> mapClass, java.lang.Class<? extends java.util.Collection> collectionClass)
          Creates a new MultiMap based on a map of a specified type and collections of a specified type.
MultiMap(MultiMap<K,V> map)
           

 

Method Summary
 boolean add(K key, V value)
          Adds a value to the collection associated with a key.
 boolean addAll(K key, java.util.Collection<V> values)
          Adds a colleciton of values to the collection associated with a key.
 boolean addAll(K key, V... values)
          Adds an array of values to the collection associated with a key.
 boolean addAll(java.util.Map<? extends K,V> map)
          Adds each value in a map to the collection associated with its key.
 void clear()
           
 boolean contains(K key, V value)
          Gets whether the collection associated with a key contains a value.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
          
 java.util.Set<java.util.Map.Entry<K,java.util.Collection<V>>> entrySet()
           
 boolean equals(java.lang.Object o)
           
 java.util.Collection<V> get(java.lang.Object key)
           
static
<K,V> MultiMap<K,V>
getMultiMap()
          Creates a new MultiMap based on a map of type LinkedHashMap and collections of type ArrayList.
static
<K,V> MultiMap<K,V>
getMultiMap(java.lang.Class<? extends java.util.Collection> collectionClass)
          Creates a new MultiMap based on a map of type LinkedHashMap and collections of a specified type.
static
<K,V> MultiMap<K,V>
getMultiMap(java.lang.Class<? extends java.util.Map> mapClass, java.lang.Class<? extends java.util.Collection> collectionClass)
          Creates a new MultiMap based on a map of a specified type and collections of a specified type.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set<K> keySet()
           
 int keysSize()
          Gets the number of keys in this map.
 java.util.Collection<V> put(K key, java.util.Collection<V> values)
          
 void putAll(java.util.Map<? extends K,? extends java.util.Collection<V>> map)
          
 V remove(K key, V value)
          Removes a value from the collection associated with a key.
 java.util.Collection<V> remove(java.lang.Object key)
           
 int size()
           
 java.lang.String toString()
           
 java.util.Collection<java.util.Collection<V>> values()
           
 int valuesSize()
          Gets the number of values in this map.
 int valuesSize(K key)
          Gets the number of values in this map associated with a key.

 

Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait

 

Constructor Detail

MultiMap

public MultiMap()
Creates a new MultiMap based on a map of type LinkedHashMap and collections of type ArrayList.

MultiMap

public MultiMap(java.lang.Class<? extends java.util.Collection> collectionClass)
Creates a new MultiMap based on a map of type LinkedHashMap and collections of a specified type.

MultiMap

public MultiMap(java.lang.Class<? extends java.util.Map> mapClass,
                java.lang.Class<? extends java.util.Collection> collectionClass)
Creates a new MultiMap based on a map of a specified type and collections of a specified type.

MultiMap

public MultiMap(MultiMap<K,V> map)

Method Detail

getMultiMap

public static <K,V> MultiMap<K,V> getMultiMap()
Creates a new MultiMap based on a map of type LinkedHashMap and collections of type ArrayList.

getMultiMap

public static <K,V> MultiMap<K,V> getMultiMap(java.lang.Class<? extends java.util.Collection> collectionClass)
Creates a new MultiMap based on a map of type LinkedHashMap and collections of a specified type.

getMultiMap

public static <K,V> MultiMap<K,V> getMultiMap(java.lang.Class<? extends java.util.Map> mapClass,
                                              java.lang.Class<? extends java.util.Collection> collectionClass)
Creates a new MultiMap based on a map of a specified type and collections of a specified type.

keysSize

public int keysSize()
Gets the number of keys in this map. Same as size(), but provided for symmetry with valuesSize().

valuesSize

public int valuesSize()
Gets the number of values in this map. This will be greater than or equal to the number of keys.

valuesSize

public int valuesSize(K key)
Gets the number of values in this map associated with a key.

contains

public boolean contains(K key,
                        V value)
Gets whether the collection associated with a key contains a value.
See Also:
Map.containsValue(Object), Collection.contains(java.lang.Object)

add

public boolean add(K key,
                   V value)
Adds a value to the collection associated with a key.
Returns:
true if the collection of values associated with the key was modified.
See Also:
put(K, java.util.Collection<V>), Collection.add(E)

addAll

public boolean addAll(K key,
                      java.util.Collection<V> values)
Adds a colleciton of values to the collection associated with a key.
Returns:
true if the collection of values associated with the key was modified.

addAll

public boolean addAll(K key,
                      V... values)
Adds an array of values to the collection associated with a key.
Returns:
true if the collection of values associated with the key was modified.

addAll

public boolean addAll(java.util.Map<? extends K,V> map)
Adds each value in a map to the collection associated with its key.
Returns:
true if any collection of values in this map was modified.
See Also:
putAll(java.util.Map ), Collection.addAll(java.util.Collection )

remove

public V remove(K key,
                V value)
Removes a value from the collection associated with a key.
Returns:
the value if it was present in the collection of values associated with the key, or null otherwise.
See Also:
remove(Object), Collection.remove(java.lang.Object)

size

public int size()
Specified by:
size in interface java.util.Map<K,java.util.Collection<V>>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<K,java.util.Collection<V>>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<K,java.util.Collection<V>>

containsValue

public boolean containsValue(java.lang.Object value)

Because of the potential ambiguity about whether the value is a V or a Collection<V>, this implementation returns true in either case.

Specified by:
containsValue in interface java.util.Map<K,java.util.Collection<V>>

get

public java.util.Collection<V> get(java.lang.Object key)
Specified by:
get in interface java.util.Map<K,java.util.Collection<V>>

put

public java.util.Collection<V> put(K key,
                                   java.util.Collection<V> values)
Specified by:
put in interface java.util.Map<K,java.util.Collection<V>>
Throws:
java.lang.IllegalArgumentException - if the type of the collection of values is not assignable to the collection class with which this multimap was constructed.

remove

public java.util.Collection<V> remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<K,java.util.Collection<V>>

putAll

public void putAll(java.util.Map<? extends K,? extends java.util.Collection<V>> map)
Specified by:
putAll in interface java.util.Map<K,java.util.Collection<V>>
Throws:
java.lang.IllegalArgumentException - if the type of a collection of values is not assignable to the collection class with which this multimap was constructed.

clear

public void clear()
Specified by:
clear in interface java.util.Map<K,java.util.Collection<V>>

keySet

public java.util.Set<K> keySet()
Specified by:
keySet in interface java.util.Map<K,java.util.Collection<V>>

values

public java.util.Collection<java.util.Collection<V>> values()
Specified by:
values in interface java.util.Map<K,java.util.Collection<V>>

entrySet

public java.util.Set<java.util.Map.Entry<K,java.util.Collection<V>>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,java.util.Collection<V>>

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map<K,java.util.Collection<V>>
Overrides:
equals in class java.lang.Object

hashCode

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

toString

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

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.7.2)

E13403-10


Copyright © 1997, 2013, Oracle. All rights reserved.