MoreCollectors { public static <T, K> Collector<T, ?, Map<K, List<T>>> groupingByAllowNullKey( Function<? super T, ? extends K> classifier) { return groupingByAllowNullKey(classifier, toList()); } private  MoreCollectors(); static Collector<Integer, ?, IntArrayList> toIntList(); static Collector<Long, ?, LongArrayList> toLongList(); static Collector<Integer, ?, IntHashSet> toIntSet(); static Collector<Long, ?, LongHashSet> toLongSet(); static Collector<T, IntObjectHashMap<U>, IntObjectHashMap<U>> toIntMap(
            ToIntFunction<? super T> keyMapper, Function<? super T, ? extends U> valueMapper); static Collector<Entry<K, V>, ?, Map<K, V>> toMap(); @Deprecated static Collector<T, ?, HashMultiset<K>> toMultiset(
            Function<? super T, ? extends K> elementMapper, ToIntFunction<? super T> countMapper); @Deprecated static Collector<T, ?, M> toMultimap(
            Function<? super T, ? extends K> keyMapper,
            Function<? super T, ? extends U> valueMapper, Supplier<M> supplier); static Collector<T, ?, R> toMap(
            Function<? super T, ? extends K> keyMapper,
            Function<? super T, ? extends U> valueMapper, Supplier<R> supplier); static Collector<T, ?, Map<K, List<T>>> groupingByAllowNullKey(
            Function<? super T, ? extends K> classifier); static Collector<T, ?, Map<K, D>> groupingByAllowNullKey(
            Function<? super T, ? extends K> classifier,
            Collector<? super T, A, D> downstream); static Collector<T, ?, M> groupingByAllowNullKey(
            Function<? super T, ? extends K> classifier,
            Supplier<M> mapFactory,
            Collector<? super T, A, D> downstream); static BinaryOperator<T> throwingMerger(); @Deprecated static Collector<T, ?, Stream<T>> concat(Stream<? extends T> other); @Deprecated static Collector<T, ?, Stream<T>> concat(T element); static final Set<Collector.Characteristics> CH_ID; static final Set<Collector.Characteristics> CH_NOID; }
@Test void groupingByAllowNullKeyTest() { Map<Integer, List<TestEnum2>> map = Stream.of(TestEnum2.values()).collect(groupingByAllowNullKey(TestEnum2::getValue)); assertEquals(5, map.size()); assertEquals(2, map.get(0).size()); assertEquals(1, map.get(null).size()); }
@Test void groupingByAllowNullKeyTest2() { assertThrows(NullPointerException.class, () -> Stream.of(TestEnum2.values()) .collect(groupingByAllowNullKey(TestEnum2::getValue, Hashtable::new, toList()))); }