Class MapUtils

    • Method Detail

      • merge

        public static <K,​V> Map<K,​V> merge​(Map<? extends K,​? extends V> map1,
                                                       Map<? extends K,​? extends V> map2)
        Merges the entries of two maps into one map. Entries of the first one have the priority (i.e. kept if same keys) over ones of the second one.
        Type Parameters:
        K - The type of the keys
        V - The type of the values
        Parameters:
        map1 - The first map (not modified)
        map2 - The second map (not modified)
        Returns:
        The merged map
      • merge

        @SafeVarargs
        public static <K,​V> Map<K,​V> merge​(Map<? extends K,​? extends V> map1,
                                                       Map<? extends K,​? extends V> map2,
                                                       Map<? extends K,​? extends V>... others)
        Merges the entries of several maps into one map. Entries of any input map one have the priority (i.e. kept if same keys) over ones of any following map.
        Type Parameters:
        K - The type of the keys
        V - The type of the values
        Parameters:
        map1 - The first map (not modified)
        map2 - The second map (not modified)
        others - The other maps (not modified)
        Returns:
        The merged map
      • merge

        public static <K,​V> Map<K,​V> merge​(BinaryOperator<V> mergeFunction,
                                                       Map<? extends K,​? extends V> map1,
                                                       Map<? extends K,​? extends V> map2)
        Merges the entries of two maps into one map.
        Type Parameters:
        K - The type of the keys
        V - The type of the values
        Parameters:
        mergeFunction - The merging function, to determine which value of the entry to keep when same keys are encountered.
        map1 - The first map (not modified)
        map2 - The second map (not modified)
        Returns:
        The merged map
      • merge

        @SafeVarargs
        public static <K,​V> Map<K,​V> merge​(BinaryOperator<V> mergeFunction,
                                                       Map<? extends K,​? extends V> map1,
                                                       Map<? extends K,​? extends V> map2,
                                                       Map<? extends K,​? extends V>... others)
        Merges the entries of several maps into one map. Entries of any input map one have the priority (i.e. kept if same keys) over ones of any following map.
        Type Parameters:
        K - The type of the keys
        V - The type of the values
        Parameters:
        mergeFunction - The merging function, to determine which value of the entry to keep when same keys are encountered.
        map1 - The first map (not modified)
        map2 - The second map (not modified)
        others - The other maps (not modified)
        Returns:
        The merged map