/** * Returns a {@link java.util.stream.Collector} which may be used in conjunction with * {@link java.util.stream.Stream#collect(java.util.stream.Collector)} to obtain a {@link HashMap}. * * @param keyMapper The key mapper * @param <K> The key type * @param <V> The value type * @param <T> Initial {@link java.util.stream.Stream} elements type * @return A {@link HashMap} Collector. */ public static <K, V, T extends V> Collector<T, ArrayList<T>, HashMap<K, V>> collector(Function<? super T, ? extends K> keyMapper) { Objects.requireNonNull(keyMapper, "keyMapper is null"); return HashMap.collector(keyMapper, v -> v); }
/** * Returns a {@link java.util.stream.Collector} which may be used in conjunction with * {@link java.util.stream.Stream#collect(java.util.stream.Collector)} to obtain a {@link HashMap}. * * @param keyMapper The key mapper * @param <K> The key type * @param <V> The value type * @param <T> Initial {@link java.util.stream.Stream} elements type * @return A {@link HashMap} Collector. */ public static <K, V, T extends V> Collector<T, ArrayList<T>, HashMap<K, V>> collector(Function<? super T, ? extends K> keyMapper) { Objects.requireNonNull(keyMapper, "keyMapper is null"); return HashMap.collector(keyMapper, v -> v); }