public static <K, V> Map<K, Set<V>> mapOfSets() { return autoExpandingMap(src -> synchronizedSet()); }
public static <K1, K2, K3, V> Map<K1, Map<K2, Map<K3, V>>> mapOfMapOfMaps() { return autoExpandingMap(src -> mapOfMaps()); }
public static <K, V> Map<K, List<V>> mapOfLists() { return autoExpandingMap(src -> synchronizedList()); }
public static <K1, K2, V> Map<K1, Map<K2, V>> mapOfMaps() { return autoExpandingMap(src -> synchronizedMap()); }
public static <K1, K2, V> Map<K1, Map<K2, List<V>>> mapOfMapOfLists() { return autoExpandingMap(src -> mapOfLists()); }
public static <K1, K2, V> Map<K1, Map<K2, Set<V>>> mapOfMapOfSets() { return autoExpandingMap(src -> mapOfSets()); }
@Override public <K, V> Map<K, V> autoExpandingInjectingMap(final Class<V> clazz) { return Coll.autoExpandingMap(src -> inject(Cls.newInstance(clazz))); }
public static <K, V> Map<K, V> autoExpandingMap(final Class<K> keyClass, final Class<V> valueClass) { try { // search for the key-based constructor final Constructor<V> constructor = valueClass.getConstructor(keyClass); return autoExpandingMap(key -> { try { return constructor.newInstance(key); } catch (Exception e) { throw U.rte(e); } }); } catch (NoSuchMethodException e) { // otherwise, use the default constructor Constructor<V> constructor; try { constructor = valueClass.getConstructor(); } catch (NoSuchMethodException e2) { throw U.rte("Couldn't find a matching constructor for the auto-expanding map!"); } final Constructor<V> defConstructor = constructor; return autoExpandingMap(key -> { try { return defConstructor.newInstance(); } catch (Exception e1) { throw U.rte(e1); } }); } }
@Override public <K, V> Map<K, V> autoExpandingInjectingMap(final Class<V> clazz) { return Coll.autoExpandingMap(new Mapper<K, V>() { @Override public V map(K src) throws Exception { return inject(Cls.newInstance(clazz)); } }); }