java.lang.Object | |
↳ | com.pnfsoftware.jeb.util.collect.Maps |
Utility methods for Map maps.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Maps() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static <K, V> List<V> |
addMulti(Map<K, List<V>> map, K key)
Add a list bucket for the key in the provided multi-map.
| ||||||||||
static <K, V, C extends Collection<V>> Collection<V> |
collectMulti(Map<K, C> map)
Collect the values of a multi-map.
| ||||||||||
static <K, V extends Comparable<V>> LinkedHashMap<K, V> |
createSortedMapByValue(Map<K, V> map, boolean ascending)
Sort a map by its values.
| ||||||||||
static <K, V> V |
get(Map<K, V> map, K key)
Get a value from a potentially null map.
| ||||||||||
static <K, V> V |
get(Map<K, V> map, K key, V safeValue)
Get a value from a potentially null map.
| ||||||||||
static <K, V extends Comparable<V>> List<Entry<K, V>> |
getSortedEntriesByValue(Map<K, V> map, boolean descending)
Retrieve a list of sorted (key,value) pairs from the provided map, sorted by values.
| ||||||||||
static <K, V extends Comparable<V>> List<Entry<K, V>> |
getSortedEntriesByValue(Map<K, V> map)
Retrieve a list of sorted (key,value) pairs from the provided map, sorted by ascending
values.
| ||||||||||
static <K, V extends Comparable<V>> List<V> |
getSortedValues(Map<K, V> map, boolean ascending)
Retrieve the values of a map, sorted by natural ascending or descending order.
| ||||||||||
static <K, V extends Comparable<V>> List<V> |
getSortedValues(Map<K, V> map)
Retrieve the values of a map, sorted by natural ascending.
| ||||||||||
static <K, V, C extends Collection<V>> boolean |
putMulti(Map<K, C> map, K key, V value, Supplier<C> supplier)
Add a key-value entry to the provided multi-map.
| ||||||||||
static <K, V> List<V> |
putMulti(Map<K, List<V>> map, K key, V value)
Add a key-value entry to the provided multi-map.
| ||||||||||
static <K, V> List<V> |
putMulti(Map<K, List<V>> map, K key, Collection<V> values)
Add a collection of key-value entries to the provided multi-map.
| ||||||||||
static <V> String |
putNoOverwrite(Map<String, V> map, String preferredKey, V value)
Insert a value to a string-key'ed map with guarantee that no existing key-value pair will be
overwritten.
| ||||||||||
static <K> boolean | removeAll(Map<K, ?> map, Collection<? extends K> keys) | ||||||||||
static <K, V> int |
removeForValue(Map<K, V> map, V v, boolean useReferenceEquality)
Remove entries that map to the provided value.
| ||||||||||
static <K, V, C extends Collection<V>> boolean |
removeMulti(Map<K, C> map, K key, V value)
Remove a key-value stored in a multi-map.
| ||||||||||
static <K> boolean | retainAll(Map<K, ?> map, Collection<? extends K> keys) | ||||||||||
static <K, V> HashMap<K, V> |
toMap(K key, V value, K key2, V value2, K key3, V value3)
Build a HashMap containing 3 elements (key, value).
| ||||||||||
static <K, V> HashMap<K, V> |
toMap(K key, V value, K key2, V value2)
Build a HashMap containing 2 elements (key, value).
| ||||||||||
static <K, V> HashMap<K, V> |
toMap(K key, V value)
Build a HashMap containing 1 element (key, value).
| ||||||||||
static <K, V> Map<K, V> |
toMap(K key, V value, Class<? extends Map> c)
Build a map containing 1 element (key, value).
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Add a list bucket for the key in the provided multi-map. If no list of values exists for the
key, a new ArrayList
is created with an initial capacity of one.
Collect the values of a multi-map.
map | a map of key-collections |
---|
Sort a map by its values. The values must be Comparable objects.
map | a map; it must not contain null values |
---|---|
ascending | true to sort by ascending order, false to sort by descending order |
Get a value from a potentially null map.
map | optional map |
---|---|
key | key |
Get a value from a potentially null map.
map | optional map |
---|---|
key | key |
safeValue | value returned if the map is null or does not contain the provided key |
Retrieve a list of sorted (key,value) pairs from the provided map, sorted by values.
map | the input map (should not contain null values) |
---|---|
descending | if true, the list is sorted by descending values instead of ascending values |
Retrieve a list of sorted (key,value) pairs from the provided map, sorted by ascending values.
map | the input map (preferably not containing null values) |
---|
Retrieve the values of a map, sorted by natural ascending or descending order. The values must be Comparable objects.
map | a map; it must not contain null values |
---|---|
ascending | true to sort by ascending order, false to sort by descending order |
Retrieve the values of a map, sorted by natural ascending. The values must be Comparable objects.
map | a map; it must not contain null values |
---|
Add a key-value entry to the provided multi-map. If no list of values exists for the key, a new list is created using the provided listFactory parameter.
map | the map |
---|---|
key | the key |
value | value to be added to the collection mapped for key |
supplier | collection factory if no collection exists and is mapped for the provided key |
add(Object)
)
Add a key-value entry to the provided multi-map. If no list of values exists for the key, a
new ArrayList
is created with an initial capacity of one (to accommodate the addition
of the value).
Equivalent to putMulti(Map, Object, Object, Supplier)
with supplier being
ArrayList::new
.
Add a collection of key-value entries to the provided multi-map. If no list of values exists
for the key, a new ArrayList
is created.
Insert a value to a string-key'ed map with guarantee that no existing key-value pair will be overwritten.
preferredKey | the preferred key for insertion |
---|
Remove entries that map to the provided value.
map | map |
---|---|
v | a non-null value |
useReferenceEquality | if true, values are compared using ==; else, they are compared using equals() |
Remove a key-value stored in a multi-map.
map | a map of key-collections |
---|
Build a HashMap containing 3 elements (key, value).
key | key |
---|---|
value | value associated to key |
key2 | 2nd key |
value2 | value associated to 2nd key |
key3 | 3rd key |
value3 | value associated to 3rd key |
Build a HashMap containing 2 elements (key, value).
key | key |
---|---|
value | value associated to key |
key2 | 2nd key |
value2 | value associated to 2nd key |
Build a HashMap containing 1 element (key, value).
key | key |
---|---|
value | value associated to key |
Build a map containing 1 element (key, value).
key | key |
---|---|
value | value associated to key |
c | optional requested map type; use null to obtain a HashMap |