Java Map Put putSafelyMap(Map> pathFeaturesMap, K1 featureDescriptor, K2 pathId, E featureValue)

Here you can find the source of putSafelyMap(Map> pathFeaturesMap, K1 featureDescriptor, K2 pathId, E featureValue)

Description

put Safely Map

License

LGPL

Declaration

static public <K1, K2, E> void putSafelyMap(Map<K1, Map<K2, E>> pathFeaturesMap, K1 featureDescriptor,
            K2 pathId, E featureValue) 

Method Source Code

//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);

    }
}

Related

  1. putOrRemove(Map map, String key, Object obj)
  2. putPairs(Map map, Object... pairs)
  3. putParameter(String key, String value, Map map)
  4. putPreferenceStoredMapValue(String keyOfPreference, String keyInMap, Object value)
  5. putRowMap(Map map, String value)
  6. putShort(Map properties, String name, short value)
  7. putToListMap(Map mapOfLists, Object key, Object val)
  8. putToMapIfNotNull(Map map, final String key, final String value)
  9. putToMapMap(Map> map1, K1 key1, K2 key2, V value)