Java Map Join join(Map dst, Map src)

Here you can find the source of join(Map dst, Map src)

Description

join

License

Apache License

Declaration

@SuppressWarnings("unchecked")
public static void join(Map<?, ?> dst, Map<?, ?> src) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;
import java.util.Map;

import java.util.Set;

public class Main {

    @SuppressWarnings("unchecked")
    public static void join(Map<?, ?> dst, Map<?, ?> src) {

        Map<Object, Object> dstMap = (Map<Object, Object>) dst;
        Map<Object, Object> srcMap = (Map<Object, Object>) src;

        Set<Object> srcKeySet = srcMap.keySet();

        for (Object srcKey : srcKeySet) {

            Object srcValue = src.get(srcKey);
            Object dstValue = dst.get(srcKey);

            if (srcValue != null) {
                if (dstValue != null) {
                    if (dstValue instanceof List) {
                        List<Object> valueList = (List<Object>) dstValue;
                        if (srcValue instanceof List) {
                            valueList.addAll((List<Object>) srcValue);
                        } else {
                            valueList.add(srcValue);
                        }/*from  w  ww .  jav  a 2s  . co  m*/
                        dstMap.put(srcKey, valueList);
                    } else if (srcValue instanceof List) {
                        List<Object> valueList = (List<Object>) srcValue;
                        valueList.add(dstValue);
                        dstMap.put(srcKey, valueList);
                    } else {
                        dstMap.put(srcKey, srcValue);
                    }
                } else {
                    dstMap.put(srcKey, srcValue);
                }
            }
        }
    }
}

Related

  1. join(final long timeout, final Map throwableMap, final Thread... threads)
  2. join(final Map map1, final Map map2, final Map... maps)
  3. join(final Map add, final Map... imports)
  4. join(List> list)
  5. Join(Map map, String entryGlue, String elementGlue)
  6. join(Map map, String separator)
  7. joinAll(Map> map, String separator)
  8. joinArgs(Map map, String sep, String split)
  9. joinLookup(Iterable elements, String separator, Map lookup)