Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**
     * Returns the map value for the given key, creating and associating a new,
     * empty {@link HashMap} if the key's value is null.
     * 
     * @param <I>
     *            The index key type.
     * @param <K>
     *            The map's key type.
     * @param <V>
     *            The map's value type.
     * @param mapMap
     *            The map to evaluate.
     * @param idxKey
     *            The index key to fetch.
     * @return A collection of values for the given key.
     */
    public static <I, K, V> Map<K, V> initMapValue(final Map<I, Map<K, V>> mapMap, final I idxKey) {
        Map<K, V> indexedMap = mapMap.get(idxKey);
        if (indexedMap == null) {
            indexedMap = new HashMap<K, V>();
            mapMap.put(idxKey, indexedMap);
        }
        return indexedMap;
    }
}