Java Map Put putAllObjects(Map targetMap, Map sourceMap)

Here you can find the source of putAllObjects(Map targetMap, Map sourceMap)

Description

put All Objects

License

Open Source License

Declaration

public static <T, U> Map<T, U> putAllObjects(Map<T, U> targetMap, Map<T, U> sourceMap) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2015 BSI Business Systems Integration AG.
 * 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
 *
 * Contributors:/*from  w  ww .  j  a  v a  2 s  .  c om*/
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static <T, U> Map<T, U> putAllObjects(Map<T, U> targetMap, Map<T, U> sourceMap) {
        if (targetMap == null && sourceMap == null) {
            return new HashMap<T, U>();
        }
        if (targetMap == null) {
            return new HashMap<T, U>(sourceMap);
        }
        if (sourceMap == null) {
            return targetMap; // nothing to add
        }
        targetMap.putAll(sourceMap);
        return targetMap;
    }
}

Related

  1. putAllIfAbsent(final Map target, final Map source)
  2. putAllIfNew(Map dest, Map source)
  3. putAllIfNotNull(final Map map, final Map m)
  4. putAllNewInMap(Map original, Map newStuff)
  5. putAllNonNullValues(Map source, Map target)
  6. putAllRecursively(Map destination, Map source)
  7. putAllTransposed( Map> source_key_valueSet, Map output_value_key)
  8. putAsCollection(K key, V value, Map map)
  9. putAsStringIfNotNull(Map properties, String key, Object value)