GuavaCollectors { public static <T, K, U> Collector<T, ?, Multimap<K, U>> toMultimap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return new MultimapCollector<T, K, U, Multimap<K, U>>(keyMapper, valueMapper) { @Override public Function<Multimap<K, U>, Multimap<K, U>> finisher() { return Function.identity(); } @Override public Set<Characteristics> characteristics() { return CharacteristicSets.IDENTITY; } }; } private  GuavaCollectors(); static Collector<T, ?, Table<R, C, V>> toTable(
            Function<? super T, ? extends R> rowMapper,
            Function<? super T, ? extends C> columnMapper,
            Function<? super T, ? extends V> valueMapper); static Collector<T, ?, Table<R, C, V>> toTable(
            Function<? super T, ? extends R> rowMapper,
            Function<? super T, ? extends C> columnMapper,
            Function<? super T, ? extends V> valueMapper,
            BinaryOperator<V> mergeFunction); static Collector<T, ?, BiMap<K, U>> toBiMap(
            Function<? super T, ? extends K> keyMapper,
            Function<? super T, ? extends U> valueMapper); static Collector<T, ?, BiMap<K, U>> toBiMap(
            Function<? super T, ? extends K> keyMapper,
            Function<? super T, ? extends U> valueMapper,
            BinaryOperator<U> mergeFunction); static Collector<T, ?, ImmutableBiMap<K, U>> toImmutableBiMap(
            Function<? super T, ? extends K> keyMapper,
            Function<? super T, ? extends U> valueMapper,
            BinaryOperator<U> mergeFunction); static Collector<T, ?, Multimap<K, U>> toMultimap(
            Function<? super T, ? extends K> keyMapper,
            Function<? super T, ? extends U> valueMapper); static Collector<T, ?, ImmutableMultimap<K, U>> toImmutableMultimap(
            Function<? super T, ? extends K> keyMapper,
            Function<? super T, ? extends U> valueMapper); static Collector<T, ?, Multiset<T>> toMultiset();  }
@Test public void testCollectToMultimap() { Multimap<String, Integer> multimap = Stream.of(1, 2).collect( GuavaCollectors.toMultimap(Object::toString, Function.identity())); Truth.assertThat(multimap).hasSize(2); Truth.assertThat(multimap).containsEntry("1", 1); Truth.assertThat(multimap).containsEntry("2", 2); }
@Test public void testDuplicatedMultimapEntry() { Multimap<String, Integer> multimap = Stream.of(10, 10).collect( GuavaCollectors.toMultimap(Object::toString, Function.identity())); Truth.assertThat(multimap).hasSize(2); Truth.assertThat(multimap.get("10")).hasSize(2); }