@Test public void toImmutableMap() throws Exception { assertEquals(ImmutableMap.of(), Stream.of() .collect(MoreCollectors.toImmutableMap(Function.identity(), Function.identity()))); ImmutableMap<String, Integer> result = Stream.of("a,1", "b,2", "c,3") .collect(MoreCollectors.toImmutableMap( item -> item.split(",")[0], item -> Integer.valueOf(item.split(",")[1]))); assertEquals(ImmutableMap.of("a", 1, "b", 2, "c", 3), result); }
public static <T, K, U> Collector<T, ?, ImmutableMap<K, U>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return Collector.of(ImmutableMap::<K, U>builder, (ImmutableMap.Builder<K, U> builder, T item) -> { builder.put(keyMapper.apply(item), valueMapper.apply(item)); }, throwingMerger(), ImmutableMap.Builder::build); }
MoreCollectors { public static <T, K, U> Collector<T, ?, ImmutableMap<K, U>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return Collector.of(ImmutableMap::<K, U>builder, (ImmutableMap.Builder<K, U> builder, T item) -> { builder.put(keyMapper.apply(item), valueMapper.apply(item)); }, throwingMerger(), ImmutableMap.Builder::build); } }
MoreCollectors { public static <T, K, U> Collector<T, ?, ImmutableMap<K, U>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return Collector.of(ImmutableMap::<K, U>builder, (ImmutableMap.Builder<K, U> builder, T item) -> { builder.put(keyMapper.apply(item), valueMapper.apply(item)); }, throwingMerger(), ImmutableMap.Builder::build); } private  MoreCollectors(); }
MoreCollectors { public static <T, K, U> Collector<T, ?, ImmutableMap<K, U>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return Collector.of(ImmutableMap::<K, U>builder, (ImmutableMap.Builder<K, U> builder, T item) -> { builder.put(keyMapper.apply(item), valueMapper.apply(item)); }, throwingMerger(), ImmutableMap.Builder::build); } private  MoreCollectors(); static Collector<T, ?, ImmutableList<T>> toImmutableList(); static Collector<T, ?, ImmutableSet<T>> toImmutableSet(); static Collector<T, ?, ImmutableMap<K, U>> toImmutableMap(//
      Function<? super T, ? extends K> keyMapper, //
      Function<? super T, ? extends U> valueMapper); }
MoreCollectors { public static <T, K, U> Collector<T, ?, ImmutableMap<K, U>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return Collector.of(ImmutableMap::<K, U>builder, (ImmutableMap.Builder<K, U> builder, T item) -> { builder.put(keyMapper.apply(item), valueMapper.apply(item)); }, throwingMerger(), ImmutableMap.Builder::build); } private  MoreCollectors(); static Collector<T, ?, ImmutableList<T>> toImmutableList(); static Collector<T, ?, ImmutableSet<T>> toImmutableSet(); static Collector<T, ?, ImmutableMap<K, U>> toImmutableMap(//
      Function<? super T, ? extends K> keyMapper, //
      Function<? super T, ? extends U> valueMapper);  }