Java Map Merge mergeMapWithAdd(Map target, Map source)

Here you can find the source of mergeMapWithAdd(Map target, Map source)

Description

merge Map With Add

License

Open Source License

Declaration

public static <TKey extends TKeyT, TKeyT> Map<? super TKey, Integer> mergeMapWithAdd(Map<TKeyT, Integer> target,
            Map<? extends TKey, ? extends Integer> source) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static <TKey extends TKeyT, TKeyT> Map<? super TKey, Integer> mergeMapWithAdd(Map<TKeyT, Integer> target,
            Map<? extends TKey, ? extends Integer> source) {
        for (Entry<? extends TKey, ? extends Integer> entry2 : source.entrySet()) {
            TKey key2 = entry2.getKey();
            int val2 = entry2.getValue();
            if (target.containsKey(key2)) {
                int val1 = target.get(key2);
                target.put(key2, val1 + val2);
            } else {
                target.put(key2, val2);
            }//www .  jav a2 s .  c  o m
        }
        return target;
    }
}

Related

  1. mergeMaps(Map map1, Map map2)
  2. mergeMaps(Map defaultMap, Map customMap)
  3. mergeMaps(Map destination, Map source)
  4. mergeMaps(Map map1, Map map2)
  5. mergeMapsIgnoreDuplicateKeys( Map first, Map second)
  6. mergeNestableMap(Map original, Map additional)
  7. mergeNsPrefixes(final Map prioritaryPrefixes, final Map additionalPrefixes)
  8. mergeOptions(Map> ssio, Map> allOptions)
  9. mergePermMap(Map> permMap, Map> subPermMap)