public class MultiMapUtils extends Object
MultiValuedMap instances.
It contains various type safe and null safe methods. Additionally, it provides the following decorators:
| Modifier and Type | Field and Description |
|---|---|
static MultiValuedMap |
EMPTY_MULTI_VALUED_MAP
An empty
UnmodifiableMultiValuedMap.
|
| Modifier and Type | Method and Description |
|---|---|
static <K |
emptyIfNull(MultiValuedMap
Returns an immutable empty
MultiValuedMap if the argument is
null, or the argument itself otherwise.
|
static <K |
emptyMultiValuedMap()
Returns immutable EMPTY_MULTI_VALUED_MAP with generic type safety.
|
static <K |
getCollection(MultiValuedMap
Gets a Collection from
MultiValuedMap in a null-safe manner.
|
static <K |
getValuesAsBag(MultiValuedMap
Gets a Bag from
MultiValuedMap in a null-safe manner.
|
static <K |
getValuesAsList(MultiValuedMap
Gets a List from
MultiValuedMap in a null-safe manner.
|
static <K |
getValuesAsSet(MultiValuedMap
Gets a Set from
MultiValuedMap in a null-safe manner.
|
static boolean |
isEmpty(MultiValuedMap
Null-safe check if the specified
MultiValuedMap is empty.
|
static <K |
newListValuedHashMap()
Creates a
ListValuedMap with an
ArrayList as collection class to store the values mapped to a key.
|
static <K |
newSetValuedHashMap()
Creates a
SetValuedMap with an
HashSet as collection class to store the values mapped to a key.
|
static <K |
transformedMultiValuedMap(MultiValuedMap
Returns a
TransformedMultiValuedMap backed by the given map.
|
static <K |
unmodifiableMultiValuedMap(MultiValuedMap
Returns an
UnmodifiableMultiValuedMap backed by the given map.
|
public static final MultiValuedMapEMPTY_MULTI_VALUED_MAP
UnmodifiableMultiValuedMap.
public static <K,V> MultiValuedMap <K ,V> emptyMultiValuedMap()
K - the type of key in the map
V - the type of value in the map
MultiValuedMap
public static <K,V> MultiValuedMap <K ,V> emptyIfNull(MultiValuedMap <K ,V> map)
MultiValuedMap if the argument is
null, or the argument itself otherwise.
K - the type of key in the map
V - the type of value in the map
map - the map, may be null
MultiValuedMap if the argument is null
public static boolean isEmpty(MultiValuedMap<? ,?> map)
MultiValuedMap is empty.
If the provided map is null, returns true.
map - the map to check, may be null
public static <K,V> Collection <V> getCollection(MultiValuedMap <K ,V> map, K key)
MultiValuedMap in a null-safe manner.
K - the key type
V - the value type
map - the
MultiValuedMap to use
key - the key to look up
MultiValuedMap, or null if input map is null
public static <K,V> List <V> getValuesAsList(MultiValuedMap <K ,V> map, K key)
MultiValuedMap in a null-safe manner.
K - the key type
V - the value type
map - the
MultiValuedMap to use
key - the key to look up
MultiValuedMap as List, or null if input map is null
public static <K,V> Set <V> getValuesAsSet(MultiValuedMap <K ,V> map, K key)
MultiValuedMap in a null-safe manner.
K - the key type
V - the value type
map - the
MultiValuedMap to use
key - the key to look up
MultiValuedMap as Set, or null if input map is null
public static <K,V> Bag <V> getValuesAsBag(MultiValuedMap <K ,V> map, K key)
MultiValuedMap in a null-safe manner.
K - the key type
V - the value type
map - the
MultiValuedMap to use
key - the key to look up
MultiValuedMap as Bag, or null if input map is null
public static <K,V> ListValuedMap <K ,V> newListValuedHashMap()
ListValuedMap with an
ArrayList as collection class to store the values mapped to a key.
K - the key type
V - the value type
ListValuedMap
public static <K,V> SetValuedMap <K ,V> newSetValuedHashMap()
SetValuedMap with an
HashSet as collection class to store the values mapped to a key.
K - the key type
V - the value type
SetValuedMap
public static <K,V> MultiValuedMap <K ,V> unmodifiableMultiValuedMap(MultiValuedMap <? extends K ,? extends V> map)
UnmodifiableMultiValuedMap backed by the given map.
K - the key type
V - the value type
map - the
MultiValuedMap to decorate, must not be null
MultiValuedMap backed by the provided map
NullPointerException - if map is null
public static <K,V> MultiValuedMap <K ,V> transformedMultiValuedMap(MultiValuedMap <K ,V> map, Transformer <? super K ,? extends K> keyTransformer, Transformer <? super V ,? extends V> valueTransformer)
TransformedMultiValuedMap backed 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, see TransformedMultiValuedMap.
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.
K - the key type
V - the value type
map - the
MultiValuedMap to transform, must not be null, typically empty
keyTransformer - the transformer for the map keys, null means no transformation
valueTransformer - the transformer for the map values, null means no transformation
MultiValuedMap backed by the given map
NullPointerException - if map is null