Java Map Put putToMapMap(Map> map1, K1 key1, K2 key2, V value)

Here you can find the source of putToMapMap(Map> map1, K1 key1, K2 key2, V value)

Description

Puts a value into a map of maps.

License

Apache License

Parameter

Parameter Description
map1 the map of maps.
key1 the key for looking up a nested map.
key2 the key for putting the value into the nested map.
value the value.

Declaration

static <K1, K2, V> void putToMapMap(Map<K1, Map<K2, V>> map1, K1 key1, K2 key2, V value) 

Method Source Code

//package com.java2s;
/*//from   w  w  w . j  a v  a 2  s. com
 * Copyright 2013 Anton Karmanov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**
     * Puts a value into a map of maps. If there is no map in the map of maps with the specified key,
     * a new {@link HashMap} is put into the map.
     * 
     * @param map1 the map of maps.
     * @param key1 the key for looking up a nested map.
     * @param key2 the key for putting the value into the nested map.
     * @param value the value.
     */
    static <K1, K2, V> void putToMapMap(Map<K1, Map<K2, V>> map1, K1 key1, K2 key2, V value) {
        Map<K2, V> map2 = map1.get(key1);
        if (map2 == null) {
            map2 = new HashMap<>();
            map1.put(key1, map2);
        }
        map2.put(key2, value);
    }
}

Related

  1. putRowMap(Map map, String value)
  2. putSafelyMap(Map> pathFeaturesMap, K1 featureDescriptor, K2 pathId, E featureValue)
  3. putShort(Map properties, String name, short value)
  4. putToListMap(Map mapOfLists, Object key, Object val)
  5. putToMapIfNotNull(Map map, final String key, final String value)
  6. putUnique(Map map, long key, V v)