public class Maps extends Object
| Modifier and Type | Method and Description |
|---|---|
static <K,E> void |
addToList(Map<K,List<E>> map,
K k,
E e)
Adds the given element to the list that is stored under the
given key.
|
static <K,V> Map<K,List<V>> |
combine(Collection<? extends Map<? extends K,? extends V>> maps)
Combine the given maps, by merging their key sets to obtain the key
set of the result list, and collecting all values from the given
input maps into lists.
|
static <T> Map<T,Integer> |
createIndexLookup(List<? extends T> list)
Create a map for looking up the indices of the elements in the given
list.
|
static <T> Map<T,Integer> |
createIndexLookupUnchecked(List<? extends T> list)
Create a map that is an index lookup for the given list.
|
static <K,V> void |
fillValues(Map<K,V> map,
Iterable<? extends V> values)
Fill the given map sequentially with the values from the given
sequence.
|
static <T> Map<Integer,T> |
fromElements(T... elements)
Creates a map that maps consecutive integer values to the
corresponding elements in the given array.
|
static <K,V> Map<K,V> |
fromEntries(Iterable<? extends Map.Entry<? extends K,? extends V>> entries)
Creates a new map from the given sequence of entries
|
static <T> Map<Integer,T> |
fromIterable(Iterable<? extends T> iterable)
Creates a map that maps consecutive integer values to the elements
in the given sequence, in the order in which they appear.
|
static <K,V> Map<K,V> |
fromIterables(Iterable<? extends K> iterable0,
Iterable<? extends V> iterable1)
Creates a map that maps the elements of the first sequence to
the corresponding elements in the second sequence.
|
static <K> Integer |
getCount(Map<K,Integer> map,
K k)
Returns the value that is stored for the given key in the given map.
|
static <K> void |
incrementCount(Map<K,Integer> map,
K k)
Increments the value that is stored for the given key in the given
map by one, or sets it to 1 if there was no value stored for the
given key.
|
static <K,V extends Number> |
sortByNumberValue(Map<K,V> map,
boolean ascending)
Sorts the given map by the double value of the values
|
static <KI,VI,KO,VO> |
transform(Map<KI,VI> map,
Function<? super KI,? extends KO> keyTransform,
Function<? super VI,? extends VO> valueTransform)
Transform the keys and values of the given map with the given
functions, and return the result as a new map.
|
static <K,V> Map<K,V> |
unmodifiableCopy(Map<? extends K,? extends V> map)
Creates an unmodifiable copy of the given map
|
public static <T> Map<T,Integer> createIndexLookupUnchecked(List<? extends T> list)
T - The element typelist - The listpublic static <T> Map<T,Integer> createIndexLookup(List<? extends T> list)
T - The element typelist - The listIllegalArgumentException - If the list contains duplicate elementspublic static <K,V> Map<K,List<V>> combine(Collection<? extends Map<? extends K,? extends V>> maps)
K - The key typeV - The value typemaps - The input mapspublic static <K,V extends Number> Map<K,V> sortByNumberValue(Map<K,V> map, boolean ascending)
K - The key typeV - The value typemap - The input mapascending - Whether the map should be sorted ascendinglypublic static <K,V> Map<K,V> fromEntries(Iterable<? extends Map.Entry<? extends K,? extends V>> entries)
K - The key typeV - The value typeentries - The entriespublic static <KI,VI,KO,VO> Map<KO,VO> transform(Map<KI,VI> map, Function<? super KI,? extends KO> keyTransform, Function<? super VI,? extends VO> valueTransform)
KI - The input key typeVI - The input value typeKO - The output key typeVO - The output value typemap - The input mapkeyTransform - The key transformvalueTransform - The value transformpublic static <K> void incrementCount(Map<K,Integer> map, K k)
K - The key typemap - The mapk - The keypublic static <K> Integer getCount(Map<K,Integer> map, K k)
K - The key typemap - The mapk - The keypublic static <K,E> void addToList(Map<K,List<E>> map, K k, E e)
K - The key typeE - The element typemap - The mapk - The keye - The elementpublic static <K,V> void fillValues(Map<K,V> map, Iterable<? extends V> values)
K - The key typeV - The value typemap - The map to fillvalues - The values@SafeVarargs public static <T> Map<Integer,T> fromElements(T... elements)
T - The value typeelements - The elementspublic static <T> Map<Integer,T> fromIterable(Iterable<? extends T> iterable)
T - The value typeiterable - The sequencepublic static <K,V> Map<K,V> fromIterables(Iterable<? extends K> iterable0, Iterable<? extends V> iterable1)
K - The key typeV - The value typeiterable0 - The first sequenceiterable1 - The second sequenceCopyright © 2020. All rights reserved.