Java Map Merge mergeMapIntoMap(Map> source, Map> destination)

Here you can find the source of mergeMapIntoMap(Map> source, Map> destination)

Description

merge Map Into Map

License

Open Source License

Declaration

public static Map<String, Set<String>> mergeMapIntoMap(Map<String, Set<String>> source,
            Map<String, Set<String>> destination) 

Method Source Code

//package com.java2s;
/*/*from w  ww. j a v  a2 s  .co  m*/
 * Copyright Siemens AG, 2014-2016.
 * With modifications by Bosch Software Innovations GmbH, 2016
 * Part of the SW360 Portal Project.
 *
 * SPDX-License-Identifier: EPL-1.0
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.*;

public class Main {
    public static Map<String, Set<String>> mergeMapIntoMap(Map<String, Set<String>> source,
            Map<String, Set<String>> destination) {
        if (destination == null) {
            return source;
        }
        if (source == null) {
            return destination;
        }
        source.keySet().stream().forEach(k -> {
            if (destination.containsKey(k)) {
                destination.get(k).addAll(source.get(k));
            } else {
                destination.put(k, source.get(k));
            }
        });
        return destination;
    }

    /**
     * Add all from right to left collection
     */
    public static <T> void addAll(Collection<T> left, Collection<T> right) {
        if (left != null && right != null) {
            left.addAll(right);
        }
    }
}

Related

  1. mergeImportedPermissionsWithExistingPermissions( Map> existingRoleIdsToActionIds, Map importedRoleIdsToActionIds)
  2. mergeListWithMap(List from, Map to)
  3. mergeMap(Map map, Object[]... pairs)
  4. mergeMap(Map primaryValues, Map defaultValues)
  5. mergeMap(Map first, Map second)
  6. mergeMapList(List> list)
  7. mergeMaps(Map m1, Map m2)
  8. mergeMaps(Map mainMap, Map defaultMap, String[] keys, boolean enforceValues)
  9. mergeMaps(Map dest, Map inserts)