Java Map Put putDeepValue(Map map, String keyPath, T v)

Here you can find the source of putDeepValue(Map map, String keyPath, T v)

Description

put Deep Value

License

Open Source License

Declaration

public static <T> void putDeepValue(Map<String, T> map, String keyPath, T v) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static <T> void putDeepValue(Map<String, T> map, String keyPath, T v) {
        HashMap subMap = (HashMap) map;

        String[] propertyPath = keyPath.toString().split("\\.");

        int j = 0;
        for (; j < propertyPath.length - 1; j++) {
            String property = propertyPath[j];
            Object value = subMap.get(property);
            if ((value == null) || !(value instanceof Map)) {
                value = new HashMap<>();
                subMap.put(property, value);
            }/*from  w w w . j a  v a  2  s . c  o m*/
            subMap = (HashMap) value;
        }
        subMap.put(propertyPath[j], v);
    }
}

Related

  1. putByFullKey(Map map, String key, Object value)
  2. putCheckedObjectInInnerMap(Map> mapValues, A key, K innerKey, V obj)
  3. putClassToMap(String extensionId, String key, Class className)
  4. putData(Map data, String name, Object value)
  5. putDataInToMap(String className, String MethodName)
  6. putIfAbsent(final Map from, final Map to)
  7. putIfAbsent(Map from, Map to)
  8. putIfAbsent(Map map, K key, V value)
  9. putIfAbsent(Map map, K key, V value)