Java Map Add addToMap(Map data, K key, T value, Class clz)

Here you can find the source of addToMap(Map data, K key, T value, Class clz)

Description

add To Map

License

Apache License

Declaration

@SuppressWarnings({ "unchecked", "rawtypes" })
    public static <K, V extends Collection<T>, T> void addToMap(Map<K, V> data, K key, T value,
            Class<? extends Collection> clz) 

Method Source Code

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

import java.util.Collection;

import java.util.Map;

public class Main {
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static <K, V extends Collection<T>, T> void addToMap(Map<K, V> data, K key, T value,
            Class<? extends Collection> clz) {
        V values = data.get(key);//from   w w w. j a  v a  2s. c o  m
        if (values == null) {
            try {
                values = (V) clz.newInstance();
            } catch (InstantiationException e) {
                throw new IllegalArgumentException("Failed to create collection class", e);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException("Failed to create collection class", e);
            }

            data.put(key, values);
        }

        values.add(value);
    }
}

Related

  1. addToListMap(Map> map, String key, String value)
  2. addToListMap(Map> map, T key, T value)
  3. addToListMap(Map> map, T key, V val)
  4. addToListMap(Map> map, TKey key, TValue value)
  5. addToMap(Map map, int initialKey, T value)
  6. addToMap(Map map, K key, V value)
  7. addToMap(Map map, K key, V value)
  8. addToMap(Map> cfs, String[] qualSplits, String[] splitQual)
  9. addToMap(Map dest, Map src)