Here you can find the source of putSafelyMap(Map
static public <K1, K2, E> void putSafelyMap(Map<K1, Map<K2, E>> pathFeaturesMap, K1 featureDescriptor, K2 pathId, E featureValue)
//package com.java2s; //License from project: LGPL import java.util.HashMap; import java.util.Map; public class Main { static public <K1, K2, E> void putSafelyMap(Map<K1, Map<K2, E>> pathFeaturesMap, K1 featureDescriptor, K2 pathId, E featureValue) { putSafelyMap(pathFeaturesMap, featureDescriptor, pathId, featureValue, HashMap.class); }/*ww w. j a v a2 s . com*/ static public <K1, K2, E> void putSafelyMap(Map<K1, Map<K2, E>> pathFeaturesMap, K1 featureDescriptor, K2 pathId, E featureValue, Class<? extends Map> Klass) { Map<K2, E> a = pathFeaturesMap.get(featureDescriptor); if (a == null) { try { a = Klass.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } ; pathFeaturesMap.put(featureDescriptor, a); } a.put(pathId, featureValue); } }