Here you can find the source of mergeCompositions( Map
public static Map<String, Integer> mergeCompositions( Map<String, Integer> target, Map<String, Integer> source)
//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; } }