Java Map Put putMapValue(String path, Object value, Map map)

Here you can find the source of putMapValue(String path, Object value, Map map)

Description

put Map Value

License

Apache License

Declaration

public static void putMapValue(String path, Object value, Map<String, Object> map) 

Method Source Code

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

import java.util.Map;

public class Main {
    public static void putMapValue(String path, Object value, Map<String, Object> map) {
        if (path == null || path.trim().isEmpty()) {
            return;
        }//from ww w .j  ava  2s  .  c  o  m

        String[] split = path.split("\\.");
        Map<String, Object> targetMap = map;
        for (int i = 0; i < split.length - 1; i++) {
            String key = split[i];
            Object intermediateMap = (Map<String, Object>) targetMap.get(key);
            if (!(intermediateMap instanceof Map)) {
                throw new IllegalArgumentException(String.format("No such property [%s].", key));
            }

            targetMap = (Map<String, Object>) intermediateMap;
        }

        targetMap.put(split[split.length - 1], value);
    }
}

Related

  1. putMapBoolean(Map params, String key)
  2. putMapBooleanList(Map params, String... keys)
  3. putMapByPair(String pair, Map m)
  4. putMapEntry(Map map, String name, String value)
  5. putMapNotNullKey(Map map, K key, V value)
  6. putModifiedAttribute(Map aMap, String name, Object value)
  7. putMultiEntry(Map map, Iterable keys, V value)
  8. putMultiple(Map map, Object key, Object value)
  9. putNotDup(Map tbl, String key, String value)