Class MultiMapUtils
- java.lang.Object
 - 
- org.apache.commons.collections4.MultiMapUtils
 
 
- 
public class MultiMapUtils extends java.lang.ObjectProvides utility methods and decorators forMultiValuedMapinstances.It contains various type safe and null safe methods. Additionally, it provides the following decorators:
- Since:
 - 4.1
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static MultiValuedMapEMPTY_MULTI_VALUED_MAPAn emptyUnmodifiableMultiValuedMap. 
- 
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
MultiValuedMap<K,V>emptyIfNull(MultiValuedMap<K,V> map)Returns an immutable emptyMultiValuedMapif the argument isnull, or the argument itself otherwise.static <K,V>
MultiValuedMap<K,V>emptyMultiValuedMap()Returns immutable EMPTY_MULTI_VALUED_MAP with generic type safety.static <K,V>
java.util.Collection<V>getCollection(MultiValuedMap<K,V> map, K key)Gets a Collection fromMultiValuedMapin a null-safe manner.static <K,V>
Bag<V>getValuesAsBag(MultiValuedMap<K,V> map, K key)Gets a Bag fromMultiValuedMapin a null-safe manner.static <K,V>
java.util.List<V>getValuesAsList(MultiValuedMap<K,V> map, K key)Gets a List fromMultiValuedMapin a null-safe manner.static <K,V>
java.util.Set<V>getValuesAsSet(MultiValuedMap<K,V> map, K key)Gets a Set fromMultiValuedMapin a null-safe manner.static booleanisEmpty(MultiValuedMap<?,?> map)Null-safe check if the specifiedMultiValuedMapis empty.static <K,V>
ListValuedMap<K,V>newListValuedHashMap()Creates aListValuedMapwith anArrayListas collection class to store the values mapped to a key.static <K,V>
SetValuedMap<K,V>newSetValuedHashMap()Creates aSetValuedMapwith anHashSetas collection class to store the values mapped to a key.static <K,V>
MultiValuedMap<K,V>transformedMultiValuedMap(MultiValuedMap<K,V> map, Transformer<? super K,? extends K> keyTransformer, Transformer<? super V,? extends V> valueTransformer)Returns aTransformedMultiValuedMapbacked by the given map.static <K,V>
MultiValuedMap<K,V>unmodifiableMultiValuedMap(MultiValuedMap<? extends K,? extends V> map)Returns anUnmodifiableMultiValuedMapbacked by the given map. 
 - 
 
- 
- 
Field Detail
- 
EMPTY_MULTI_VALUED_MAP
public static final MultiValuedMap EMPTY_MULTI_VALUED_MAP
An emptyUnmodifiableMultiValuedMap. 
 - 
 
- 
Method Detail
- 
emptyMultiValuedMap
public static <K,V> MultiValuedMap<K,V> emptyMultiValuedMap()
Returns immutable EMPTY_MULTI_VALUED_MAP with generic type safety.- Type Parameters:
 K- the type of key in the mapV- the type of value in the map- Returns:
 - immutable and empty 
MultiValuedMap 
 
- 
emptyIfNull
public static <K,V> MultiValuedMap<K,V> emptyIfNull(MultiValuedMap<K,V> map)
Returns an immutable emptyMultiValuedMapif the argument isnull, or the argument itself otherwise.- Type Parameters:
 K- the type of key in the mapV- the type of value in the map- Parameters:
 map- the map, may be null- Returns:
 - an empty 
MultiValuedMapif the argument is null 
 
- 
isEmpty
public static boolean isEmpty(MultiValuedMap<?,?> map)
Null-safe check if the specifiedMultiValuedMapis empty.If the provided map is null, returns true.
- Parameters:
 map- the map to check, may be null- Returns:
 - true if the map is empty or null
 
 
- 
getCollection
public static <K,V> java.util.Collection<V> getCollection(MultiValuedMap<K,V> map, K key)
Gets a Collection fromMultiValuedMapin a null-safe manner.- Type Parameters:
 K- the key typeV- the value type- Parameters:
 map- theMultiValuedMapto usekey- the key to look up- Returns:
 - the Collection in the 
MultiValuedMap, or null if input map is null 
 
- 
getValuesAsList
public static <K,V> java.util.List<V> getValuesAsList(MultiValuedMap<K,V> map, K key)
Gets a List fromMultiValuedMapin a null-safe manner.- Type Parameters:
 K- the key typeV- the value type- Parameters:
 map- theMultiValuedMapto usekey- the key to look up- Returns:
 - the Collection in the 
MultiValuedMapas List, or null if input map is null 
 
- 
getValuesAsSet
public static <K,V> java.util.Set<V> getValuesAsSet(MultiValuedMap<K,V> map, K key)
Gets a Set fromMultiValuedMapin a null-safe manner.- Type Parameters:
 K- the key typeV- the value type- Parameters:
 map- theMultiValuedMapto usekey- the key to look up- Returns:
 - the Collection in the 
MultiValuedMapas Set, or null if input map is null 
 
- 
getValuesAsBag
public static <K,V> Bag<V> getValuesAsBag(MultiValuedMap<K,V> map, K key)
Gets a Bag fromMultiValuedMapin a null-safe manner.- Type Parameters:
 K- the key typeV- the value type- Parameters:
 map- theMultiValuedMapto usekey- the key to look up- Returns:
 - the Collection in the 
MultiValuedMapas Bag, or null if input map is null 
 
- 
newListValuedHashMap
public static <K,V> ListValuedMap<K,V> newListValuedHashMap()
Creates aListValuedMapwith anArrayListas collection class to store the values mapped to a key.- Type Parameters:
 K- the key typeV- the value type- Returns:
 - a new 
ListValuedMap 
 
- 
newSetValuedHashMap
public static <K,V> SetValuedMap<K,V> newSetValuedHashMap()
Creates aSetValuedMapwith anHashSetas collection class to store the values mapped to a key.- Type Parameters:
 K- the key typeV- the value type- Returns:
 - a new 
SetValuedMap 
 
- 
unmodifiableMultiValuedMap
public static <K,V> MultiValuedMap<K,V> unmodifiableMultiValuedMap(MultiValuedMap<? extends K,? extends V> map)
Returns anUnmodifiableMultiValuedMapbacked by the given map.- Type Parameters:
 K- the key typeV- the value type- Parameters:
 map- theMultiValuedMapto decorate, must not be null- Returns:
 - an unmodifiable 
MultiValuedMapbacked by the provided map - Throws:
 java.lang.NullPointerException- if map is null
 
- 
transformedMultiValuedMap
public static <K,V> MultiValuedMap<K,V> transformedMultiValuedMap(MultiValuedMap<K,V> map, Transformer<? super K,? extends K> keyTransformer, Transformer<? super V,? extends V> valueTransformer)
Returns aTransformedMultiValuedMapbacked by the given map.This method returns a new
MultiValuedMap(decorating the specified map) that will transform any new entries added to it. Existing entries in the specified map will not be transformed. If you want that behaviour, seeTransformedMultiValuedMap.transformedMap(org.apache.commons.collections4.MultiValuedMap<K, V>, org.apache.commons.collections4.Transformer<? super K, ? extends K>, org.apache.commons.collections4.Transformer<? super V, ? extends V>).Each object is passed through the transformers as it is added to the Map. It is important not to use the original map after invoking this method, as it is a back door for adding untransformed objects.
If there are any elements already in the map being decorated, they are NOT transformed.
- Type Parameters:
 K- the key typeV- the value type- Parameters:
 map- theMultiValuedMapto transform, must not be null, typically emptykeyTransformer- the transformer for the map keys, null means no transformationvalueTransformer- the transformer for the map values, null means no transformation- Returns:
 - a transformed 
MultiValuedMapbacked by the given map - Throws:
 java.lang.NullPointerException- if map is null
 
 - 
 
 -