Java Map Merge mergeCompositions( Map target, Map source)

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

Description

merge Compositions

License

Open Source License

Declaration

public static Map<String, Integer> mergeCompositions(
            Map<String, Integer> target, Map<String, Integer> source) 

Method Source Code

//package com.java2s;
/*// ww  w. j  av a 2s  .  c o  m
 * This file is part of cBioPortal Cancer Hotspots.
 *
 * cBioPortal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Map;

public class Main {
    public static Map<String, Integer> mergeCompositions(
            Map<String, Integer> target, Map<String, Integer> source) {
        if (source == null || target == null) {
            return target;
        }

        for (String key : source.keySet()) {
            Integer value = target.get(key);

            // if no value yet, just copy from the source
            if (value == null) {
                target.put(key, source.get(key));
            }
            // if already exists add to the current value
            else {
                target.put(key, value + source.get(key));
            }
        }

        return target;
    }
}

Related

  1. merge(Map map1, Map map2)
  2. merge(Map mapPriorityLeast, Map mapPriorityFirst)
  3. mergeAggCompStatsTopoPageSpout(Map accSpoutStats, Map spoutStats)
  4. mergeBootArgumentsIntoMap(String[] args, Map map)
  5. mergeCompactedValue(Map obj, String key, Object value)
  6. mergeConfig(Map userConfig, Map referenceConfig)
  7. mergeCounterMap(Map map, String key, Object value)
  8. mergeCountMaps(Map base, Map other)
  9. mergeCounts(Map counter, String key)