### Question:
ImmutableCollectors { public static <T, K, V> Collector<T, ?, Map<K, V>> toMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { return Collector.of( ImmutableMap::<K, V>builder, (map, item) -> map.put(keyMapper.apply(item), valueMapper.apply(item)), (x, y) -> { x.putAll(y.build()); return x; }, ImmutableMap.Builder::build); }  static Collector<T, ?, List<T>> toList(); static Collector<T, ?, Map<K, V>> toMap(
        Function<? super T, ? extends K> keyMapper,
        Function<? super T, ? extends V> valueMapper); static Collector<T, ?, Map<K, T>> toMap(Function<? super T, ? extends K> keyMapper);  }### Answer:
@Test void toMap() { String item0 = "foo"; String item1 = "bar"; Map<String, String> map = Stream.of(item0, item1).collect(ImmutableCollectors.toMap(Functions.identity())); assertThat(map).containsExactly( new AbstractMap.SimpleImmutableEntry<>(item0, item0), new AbstractMap.SimpleImmutableEntry<>(item1, item1)); }
@Test void toMapImmutable() { Map<String, String> map = Stream.<String>empty().collect(ImmutableCollectors.toMap(Function.identity())); assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> map.put("foo", "foo")); }
@Test void toMapParallel() { String item0 = "foo"; String item1 = "bar"; Map<String, String> map = Arrays.asList(item0, item1) .parallelStream() .collect(ImmutableCollectors.toMap(Functions.identity())); assertThat(map).containsExactly( new AbstractMap.SimpleImmutableEntry<>(item0, item0), new AbstractMap.SimpleImmutableEntry<>(item1, item1)); }