Here you can find the source of putCheckedObjectInInnerMap(Map> mapValues, A key, K innerKey, V obj)
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 |
@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)
//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; } }