Class MapUtils

java.lang.Object
org.gbif.utils.collection.MapUtils

public class MapUtils extends Object
  • Method Details

    • sortByValue

      public 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 new LinkedHashMap which maintains that order.
      Type Parameters:
      K - type of the map key
      V - type of the map value, this needs to implement Comparable
      Parameters:
      map - to sort
      Returns:
      a map ordered by the values of the input map
    • sortByValue

      public 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 new LinkedHashMap which maintains that order.
      Type Parameters:
      K - type of the map key
      V - type of the map value
      Parameters:
      map - to sort
      Returns:
      a map ordered by the values of the input map
    • getOrDefault

      public static <K, V> V getOrDefault(Map<K,V> map, K key, V defaultValue)
      Returns a maps value or a given default if not present. For pre java8 code since j8 introduced Map.getOrDefault.