public final class MapUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <K,V> java.util.Map<K,V> |
copyOf(java.util.Map<? extends K,? extends V> map)
Creates an immutable copy of the given map.
|
static <K,V> java.util.Map.Entry<K,V> |
entry(K key,
V value)
Creates an immutable
Map.Entry from the given key and value. |
static <K,V> java.util.Map<K,V> |
of()
Returns an unmodifiable map containing zero mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1)
Returns an unmodifiable map containing a single mapping.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2)
Returns an unmodifiable map containing two mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3)
Returns an unmodifiable map containing three mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4)
Returns an unmodifiable map containing four mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5)
Returns an unmodifiable map containing five mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6)
Returns an unmodifiable map containing six mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7)
Returns an unmodifiable map containing seven mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8)
Returns an unmodifiable map containing eight mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9)
Returns an unmodifiable map containing nine mappings.
|
static <K,V> java.util.Map<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9,
K k10,
V v10)
Returns an unmodifiable map containing ten mappings.
|
static <K,V> java.util.Map<K,V> |
ofEntries(java.util.Map.Entry<? extends K,? extends V>... entries)
Creates an unmodifiable Map from an array of
Map.Entry values. |
static <K,V> java.util.Map<K,V> |
orderedCopyOf(java.util.Map<? extends K,? extends V> map)
Creates an ordered immutable copy of the given map.
|
static <T,K,U> java.util.stream.Collector<T,?,java.util.Map<K,U>> |
toUnmodifiableMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends U> valueMapper)
Creates a collector that collects into an unmodifiable Map.
|
public static <K,V> java.util.Map<K,V> copyOf(java.util.Map<? extends K,? extends V> map)
K - the Map's key typeV - the Map's value typemap - The map to make an immutable copy ofpublic static <K,V> java.util.Map<K,V> orderedCopyOf(java.util.Map<? extends K,? extends V> map)
K - the Map's key typeV - the Map's value typemap - The map to make an immutable copy ofpublic static <K,V> java.util.Map<K,V> of()
K - the Map's key typeV - the Map's value typepublic static <K,V> java.util.Map<K,V> of(K k1,
V v1)
K - the Map's key typeV - the Map's value typek1 - the mapping's keyv1 - the mapping's valuejava.lang.NullPointerException - if the key or the value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuejava.lang.IllegalArgumentException - if the keys are duplicatesjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuek4 - the fourth mapping's keyv4 - the fourth mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuek4 - the fourth mapping's keyv4 - the fourth mapping's valuek5 - the fifth mapping's keyv5 - the fifth mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuek4 - the fourth mapping's keyv4 - the fourth mapping's valuek5 - the fifth mapping's keyv5 - the fifth mapping's valuek6 - the sixth mapping's keyv6 - the sixth mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuek4 - the fourth mapping's keyv4 - the fourth mapping's valuek5 - the fifth mapping's keyv5 - the fifth mapping's valuek6 - the sixth mapping's keyv6 - the sixth mapping's valuek7 - the seventh mapping's keyv7 - the seventh mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuek4 - the fourth mapping's keyv4 - the fourth mapping's valuek5 - the fifth mapping's keyv5 - the fifth mapping's valuek6 - the sixth mapping's keyv6 - the sixth mapping's valuek7 - the seventh mapping's keyv7 - the seventh mapping's valuek8 - the eighth mapping's keyv8 - the eighth mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuek4 - the fourth mapping's keyv4 - the fourth mapping's valuek5 - the fifth mapping's keyv5 - the fifth mapping's valuek6 - the sixth mapping's keyv6 - the sixth mapping's valuek7 - the seventh mapping's keyv7 - the seventh mapping's valuek8 - the eighth mapping's keyv8 - the eighth mapping's valuek9 - the ninth mapping's keyv9 - the ninth mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map<K,V> of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9,
K k10,
V v10)
K - the Map's key typeV - the Map's value typek1 - the first mapping's keyv1 - the first mapping's valuek2 - the second mapping's keyv2 - the second mapping's valuek3 - the third mapping's keyv3 - the third mapping's valuek4 - the fourth mapping's keyv4 - the fourth mapping's valuek5 - the fifth mapping's keyv5 - the fifth mapping's valuek6 - the sixth mapping's keyv6 - the sixth mapping's valuek7 - the seventh mapping's keyv7 - the seventh mapping's valuek8 - the eighth mapping's keyv8 - the eighth mapping's valuek9 - the ninth mapping's keyv9 - the ninth mapping's valuek10 - the tenth mapping's keyv10 - the tenth mapping's valuejava.lang.IllegalArgumentException - if there are any duplicate keysjava.lang.NullPointerException - if any key or value is nullpublic static <K,V> java.util.Map.Entry<K,V> entry(K key,
V value)
Map.Entry from the given key and value.K - Key type.V - Value type.key - Key to set in the Map.Entry.value - Value to set in the Map.Entry.java.lang.NullPointerException - if the key or value are null.@SafeVarargs public static <K,V> java.util.Map<K,V> ofEntries(java.util.Map.Entry<? extends K,? extends V>... entries)
Map.Entry values.K - Map key type.V - Map value type.entries - Map entries to add to the created Map.public static <T,K,U> java.util.stream.Collector<T,?,java.util.Map<K,U>> toUnmodifiableMap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends U> valueMapper)
This is a polyfill equivalent of Java 10's
Collectors#toUnmodifiableMap.
T - the type to retrieve keys and values from.K - the Map's key type.U - the Map's value type.keyMapper - Function that retrieves the key.valueMapper - Function that retrieves the value.