Package org.gbif.utils.collection
Class MapUtils
java.lang.Object
org.gbif.utils.collection.MapUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> V getOrDefault(Map<K, V> map, K key, V defaultValue) Returns a maps value or a given default if not present.static <K,V extends Comparable<? super V>>
Map<K,V> sortByValue(Map<K, V> map) This orders a Map by its values and returns a newLinkedHashMapwhich maintains that order.static <K,V> Map<K, V> sortByValue(Map<K, V> map, Comparator<V> comparator) Order a Map by its values using the given value comparator and return a newLinkedHashMapwhich maintains that order.
-
Method Details
-
sortByValue
This orders a Map by its values and returns a newLinkedHashMapwhich maintains that order.- Type Parameters:
K- type of the map keyV- type of the map value, this needs to implementComparable- Parameters:
map- to sort- Returns:
- a map ordered by the values of the input map
-
sortByValue
Order a Map by its values using the given value comparator and return a newLinkedHashMapwhich maintains that order.- Type Parameters:
K- type of the map keyV- type of the map value- Parameters:
map- to sort- Returns:
- a map ordered by the values of the input map
-
getOrDefault
Returns a maps value or a given default if not present. For pre java8 code since j8 introduced Map.getOrDefault.
-