Java Map Put putAllIfNew(Map dest, Map source)

Here you can find the source of putAllIfNew(Map dest, Map source)

Description

Same as putall, except if the property already exists in the dest map, don't move it.

License

Open Source License

Parameter

Parameter Description
dest a parameter
source a parameter

Declaration

public static Map<String, Object> putAllIfNew(Map<String, Object> dest, Map<String, Object> source) 

Method Source Code

//package com.java2s;

import java.util.Map;

public class Main {
    /**//from  ww w.j a  va  2  s  . c om
     * Same as putall, except if the property already exists in the dest map, don't move it.
     * TODO Convert this to generics.
     * @param dest
     * @param source
     * @return
     */
    public static Map<String, Object> putAllIfNew(Map<String, Object> dest, Map<String, Object> source) {
        if (dest == null)
            return source;
        if (source == null)
            return dest;
        for (String key : source.keySet()) {
            if (dest.get(key) == null)
                dest.put(key, source.get(key));
        }
        return dest;
    }
}

Related

  1. putAll(Map map, Map otherMap)
  2. putAll(Map map, Object... keysAndValues)
  3. putAll(Map model, String prefix, Map subModel)
  4. putAll(Map map, String prefix, Map values)
  5. putAllIfAbsent(final Map target, final Map source)
  6. putAllIfNotNull(final Map map, final Map m)
  7. putAllNewInMap(Map original, Map newStuff)
  8. putAllNonNullValues(Map source, Map target)
  9. putAllObjects(Map targetMap, Map sourceMap)