Class MapUtil


  • public final class MapUtil
    extends java.lang.Object
    Utility class for work with collections. Not for public use.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int HASH_MULTIPLIER  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MapUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      boolean
      equals​(java.util.Map<K,​V> m1, java.util.Map<K,​V> m2)
      Checks if two maps are equal: the are of the same types and has equal number of stored entries and both has the same set of keys ans each key is associated with an appropriate value.
      static <K,​V>
      int
      getHashCode​(java.util.Map<K,​V> m1)
      Calculates the hash code of the map.
      static <K,​V>
      void
      merge​(java.util.Map<K,​V> destination, java.util.Map<K,​V> source, java.util.function.BiFunction<V,​V,​V> valuesMerger)
      Merges data from source Map into destination Map using provided function if key exists in both Maps.
      static <K,​V>
      void
      putIfNotNull​(java.util.Map<K,​V> map, K key, V value)
      Puts value to map if the value is not null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MapUtil

        private MapUtil()
    • Method Detail

      • equals

        public static <K,​V> boolean equals​(java.util.Map<K,​V> m1,
                                                 java.util.Map<K,​V> m2)
        Checks if two maps are equal: the are of the same types and has equal number of stored entries and both has the same set of keys ans each key is associated with an appropriate value.
        Type Parameters:
        K - is a type of keys
        V - is a type of values
        Parameters:
        m1 - is the first map
        m2 - is the second map
        Returns:
        true if maps are equal and false otherwise
      • merge

        public static <K,​V> void merge​(java.util.Map<K,​V> destination,
                                             java.util.Map<K,​V> source,
                                             java.util.function.BiFunction<V,​V,​V> valuesMerger)
        Merges data from source Map into destination Map using provided function if key exists in both Maps. If key doesn't exist in destination Map in will be putted directly.
        Type Parameters:
        K - is a type of keys
        V - is a type of values
        Parameters:
        destination - Map to which data will be merged.
        source - Map from which data will be taken.
        valuesMerger - function which will be used to merge Maps values.
      • getHashCode

        public static <K,​V> int getHashCode​(java.util.Map<K,​V> m1)
        Calculates the hash code of the map.
        Type Parameters:
        K - is a type of keys
        V - is a type of values
        Parameters:
        m1 - is the map
        Returns:
        the hash code of the map.
      • putIfNotNull

        public static <K,​V> void putIfNotNull​(java.util.Map<K,​V> map,
                                                    K key,
                                                    V value)
        Puts value to map if the value is not null.
        Type Parameters:
        K - is a type of key
        V - is a type of value
        Parameters:
        map - the map in which value can be pushed
        key - the key
        value - the value