public final class MapUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static SortedMap |
EMPTY_SORTED_MAP
Desperately missing from
java.util.Collections. |
| Modifier and Type | Method and Description |
|---|---|
static <K,V> Map<K,V> |
augment(Map<K,V> delegate,
K extraKey,
V extraValue)
Returns a
Map that is composed of the delegate and one extra entry. |
static <K,V> Map<K,V> |
combine(Map<K,V> map1,
Map<K,V> map2)
Returns a
Map that is composed of map1 and map2, where map1 takes
precedence over <map2. |
static <K,V> SortedMap<K,V> |
emptySortedMap()
Desperately missing from
java.util.Collections. |
static <K,V> Map.Entry<K,V> |
entry(K key,
V initialValue) |
static boolean |
equal(Object o1,
Object o2)
Deprecated.
Moved to
ObjectUtil.equals(Object, Object) |
static <K,V> Map<K,V> |
fromMappings(Object... keysAndValues)
Deprecated.
Use
map(Object...) instead |
static <K,V> HashMap<K,V> |
hashMapOf(int initialCapacity,
Map.Entry<? extends K,? extends V>... entries) |
static <K,V> HashMap<K,V> |
hashMapOf(Map.Entry<? extends K,? extends V>... entries)
Creates, fills and returns a
HashMap. |
static <K,V,I> Map<K,V> |
lazyMap(Map<K,Function<? super I,? extends V>> valueGetters,
I in)
Creates and returns map that computes values only on demand, e.g. when
Map.entrySet().iterator().next().getValue() is invoked, by calling valueGetters.get(key).call(in). |
static <K,V> Map<K,V> |
lazyMap(Map<K,Producer<? extends V>> valueGetters)
Creates and returns a map that produces values through the valueGetters map only when they are
needed.
|
static <K,V> Map<K,V> |
map(K[] keys,
V[] values)
Returns an unmodifiable map, mapping the given key-value pairs.
|
static <K,V> Map<K,V> |
map(Object... keyValuePairs)
Returns an unmodifiable map, mapping the given key-value pairs.
|
static <K,V> Map<K,V> |
override(Map<K,V> delegate,
K extraKey,
V extraValue)
Returns a
Map that is composed of the delegate and one extra entry. |
static <K,V,M extends Map<K,V>> |
putAll(M subject,
boolean allowDuplicateKeys,
Map.Entry<? extends K,? extends V>... entries)
Puts all entries into the subject.
|
static <K,V,M extends Map<K,V>> |
putAll(M subject,
Map.Entry<? extends K,? extends V>... entries)
Puts all entries into the subject.
|
static <K,V1,V2> Map<K,V2> |
transformingMap(Map<K,? extends V1> delegate,
Function<V1,V2> transformer)
Wraps the delegate map such that values are fed through the transformer whenever they
are needed.
|
static <K,V> TreeMap<K,V> |
treeMapOf(Map.Entry<? extends K,? extends V>... entries) |
public static final SortedMap EMPTY_SORTED_MAP
java.util.Collections.public static <K,V> Map<K,V> map(Object... keyValuePairs)
null keys and null values are
supported.keyValuePairs - An alternating sequence of keys and valuesArrayIndexOutOfBoundsException - The length of keyValuePairs is oddIllegalArgumentException - Two of the keys are equalpublic static <K,V> Map<K,V> map(K[] keys, V[] values)
null keys and null values are
supported.ArrayIndexOutOfBoundsException - The length of keyValuePairs is oddIllegalArgumentException - Two of the keys are equalpublic static <K,V> HashMap<K,V> hashMapOf(Map.Entry<? extends K,? extends V>... entries)
HashMap. The initial capacity of the HashMap is chosen to be
optimal for the number of entries.HashMap containing all entriesIllegalArgumentException - Two entries have equal keyspublic static <K,V> HashMap<K,V> hashMapOf(int initialCapacity, Map.Entry<? extends K,? extends V>... entries)
initialCapacity - See the documentation of HashMapHashMap containing all entriesIllegalArgumentException - Two entries have equal keyspublic static <K,V> TreeMap<K,V> treeMapOf(Map.Entry<? extends K,? extends V>... entries)
TreeMap containing all entriesIllegalArgumentException - Two entries have equal keyspublic static <K,V,M extends Map<K,V>> M putAll(M subject, Map.Entry<? extends K,? extends V>... entries)
IllegalArgumentException - Two entries have equal keyspublic static <K,V,M extends Map<K,V>> M putAll(M subject, boolean allowDuplicateKeys, Map.Entry<? extends K,? extends V>... entries)
IllegalArgumentException - Two entries have equal keys, and allowDuplicateKeys is
falsepublic static <K,V> Map.Entry<K,V> entry(K key, V initialValue)
Map.Entry with the given key and the
initialValueMap.Entry.setValue(Object)public static <K,V> SortedMap<K,V> emptySortedMap()
java.util.Collections.public static <K,V> Map<K,V> combine(Map<K,V> map1, Map<K,V> map2)
Map that is composed of map1 and map2, where map1 takes
precedence over <map2.
All modifying operations are directed to map1; map2 is never modified.
public static <K,V> Map<K,V> augment(Map<K,V> delegate, K extraKey, V extraValue)
Map that is composed of the delegate and one extra entry. If the delegate
contains the extraKey, then the value from the delegate takes precedence.public static <K,V> Map<K,V> override(Map<K,V> delegate, K extraKey, V extraValue)
Map that is composed of the delegate and one extra entry. If the delegate
contains the extraKey, then the extraValue takes precedence.@Deprecated public static boolean equal(@Nullable Object o1, @Nullable Object o2)
ObjectUtil.equals(Object, Object)@Deprecated public static <K,V> Map<K,V> fromMappings(Object... keysAndValues)
map(Object...) insteadpublic static <K,V,I> Map<K,V> lazyMap(Map<K,Function<? super I,? extends V>> valueGetters, @Nullable I in)
Map.entrySet().iterator().next().getValue() is invoked, by calling valueGetters.get(key).call(in). (in is the value of this method's in parameter,
and can be used to convey "context information" to the valueGetters.)
The returned map supports entry removal operations iff the valueGetters map supports them.
The returned map does not support Map.put(Object, Object) and Map.putAll(Map)
operations.
The returned map is backed by the valueGetters map, i.e. modifications to either of the two maps is reflected by the other map.
The returned map supports null keys iff the valueGetters map supports null keys.
The returned map may return null values if there is no value getter for the key, or if the value
getter returns null.
valueGetters - Must not contain null valuespublic static <K,V> Map<K,V> lazyMap(Map<K,Producer<? extends V>> valueGetters)
Copyright © 2022 Arno Unkrig. All rights reserved.