Here you can find the source of mergeMaps(Map
Merges the source map into the destination.
Parameter | Description |
---|---|
destination | a parameter |
source | a parameter |
public static void mergeMaps(Map<String, String> destination, Map<String, String> source)
//package com.java2s; /*//w w w .ja v a2 s .c o m * FrontlineSMS <http://www.frontlinesms.com> * Copyright 2007, 2008 kiwanja * * This file is part of FrontlineSMS. * * FrontlineSMS is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at * your option) any later version. * * FrontlineSMS 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 Lesser * General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with FrontlineSMS. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Map; public class Main { /** * <p> * Merges the source map into the destination. Values in the destination * take precedence - they will not be overridden if the same key occurs in * both destination and source. * </p> * <p> * If a <code>null</code> source is provided, this method does nothing; if a * <code>null</code> destination is provided, a {@link NullPointerException} * will be thrown. * * @param destination * @param source */ public static void mergeMaps(Map<String, String> destination, Map<String, String> source) { assert (destination != null) : "You must provide a destination map to merge into."; // If there is nothing to merge, just return. if (source == null) return; for (String key : source.keySet()) { if (destination.get(key) != null) { // key already present in language bundle - ignoring } else { // this key does not appear in the language bundle, so add it // with the value from the map destination.put(key, source.get(key)); } } } }