Java Map Put putCheckedObjectInInnerMap(Map> mapValues, A key, K innerKey, V obj)

Here you can find the source of putCheckedObjectInInnerMap(Map> mapValues, A key, K innerKey, V obj)

Description

Puts an object to an inner Map of the given Map ( initializes it first if null )

License

Open Source License

Parameter

Parameter Description
mapValues : the Map to insert the object into
key : the key under which the object is to be inserted
innerKey : the key under which the object is to be inserted
obj : the Object to be inserted

Return

the updated Map

Declaration

@SuppressWarnings("unchecked")
public static <A, K, V> Map<A, Map<K, V>> putCheckedObjectInInnerMap(Map<A, Map<K, V>> mapValues, A key,
        K innerKey, V obj) 

Method Source Code

//package com.java2s;

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**//from   ww  w.j  av  a2s.c o  m
     * Puts an object to an inner Map of the given Map ( initializes it first if null )
     *
     * @param mapValues : the Map to insert the object into
     * @param key       : the key under which the object is to be inserted
     * @param innerKey  : the key under which the object is to be inserted
     * @param obj       : the Object to be inserted
     * @return the updated Map
     */
    @SuppressWarnings("unchecked")
    public static <A, K, V> Map<A, Map<K, V>> putCheckedObjectInInnerMap(Map<A, Map<K, V>> mapValues, A key,
            K innerKey, V obj) {
        Map<K, V> innerMap = null;
        if (mapValues != null && mapValues.containsKey(key)) {
            innerMap = mapValues.get(key);
        }
        innerMap = addCheckedObjectInMap(innerMap, innerKey, obj);
        mapValues = addCheckedObjectInMap(mapValues, key, innerMap);
        return mapValues;
    }

    /**
     * Puts an object to a given Map ( initializes it first if null )
     *
     * @param mapValues : the Map to insert the object into
     * @param key       : the key under which the object is to be inserted
     * @param obj       : the Object to be inserted
     * @return the updated Map
     */
    @SuppressWarnings("unchecked")
    public static <K, V, O extends V> Map<K, V> addCheckedObjectInMap(Map<K, V> mapValues, K key, O obj) {
        if (obj != null) {
            if (mapValues == null) {
                mapValues = new HashMap<>();
            }
            mapValues.put(key, obj);
        }
        return mapValues;
    }
}

Related

  1. putAsCollection(K key, V value, Map map)
  2. putAsStringIfNotNull(Map properties, String key, Object value)
  3. putAt(LinkedHashMap map, K key, V value, int pos)
  4. putBoolean(Map properties, Object key, boolean value)
  5. putByFullKey(Map map, String key, Object value)
  6. putClassToMap(String extensionId, String key, Class className)
  7. putData(Map data, String name, Object value)
  8. putDataInToMap(String className, String MethodName)
  9. putDeepValue(Map map, String keyPath, T v)