@Test public void testToImmutableMap_Sort() { List<Data> vals = Arrays.asList(new Data(22, "a"), new Data(11, "bb"), new Data(231, "cc"), new Data(1231, "cc")); ImmutableMap<Integer, String> res = vals.stream().collect(toImmutableMap(d -> d.ii, d -> d.ss)); assertEquals("{22=a, 11=bb, 231=cc, 1231=cc}", res.toString()); }
public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { Supplier<ImmutableMap.Builder<K, V>> supplier = ImmutableMap.Builder::new; BiConsumer<ImmutableMap.Builder<K, V>, T> accumulator = (b, t) -> b.put(keyMapper.apply(t), valueMapper.apply(t)); BinaryOperator<ImmutableMap.Builder<K, V>> combiner = (l, r) -> l.putAll(r.build()); Function<ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> finisher = ImmutableMap.Builder::build; return Collector.of(supplier, accumulator, combiner, finisher); }
Gullectors { public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { Supplier<ImmutableMap.Builder<K, V>> supplier = ImmutableMap.Builder::new; BiConsumer<ImmutableMap.Builder<K, V>, T> accumulator = (b, t) -> b.put(keyMapper.apply(t), valueMapper.apply(t)); BinaryOperator<ImmutableMap.Builder<K, V>> combiner = (l, r) -> l.putAll(r.build()); Function<ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> finisher = ImmutableMap.Builder::build; return Collector.of(supplier, accumulator, combiner, finisher); } }
Gullectors { public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { Supplier<ImmutableMap.Builder<K, V>> supplier = ImmutableMap.Builder::new; BiConsumer<ImmutableMap.Builder<K, V>, T> accumulator = (b, t) -> b.put(keyMapper.apply(t), valueMapper.apply(t)); BinaryOperator<ImmutableMap.Builder<K, V>> combiner = (l, r) -> l.putAll(r.build()); Function<ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> finisher = ImmutableMap.Builder::build; return Collector.of(supplier, accumulator, combiner, finisher); }  }
Gullectors { public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { Supplier<ImmutableMap.Builder<K, V>> supplier = ImmutableMap.Builder::new; BiConsumer<ImmutableMap.Builder<K, V>, T> accumulator = (b, t) -> b.put(keyMapper.apply(t), valueMapper.apply(t)); BinaryOperator<ImmutableMap.Builder<K, V>> combiner = (l, r) -> l.putAll(r.build()); Function<ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> finisher = ImmutableMap.Builder::build; return Collector.of(supplier, accumulator, combiner, finisher); }  static Collector<T, ?, ImmutableList<T>> toImmutableList(); static Collector<T, ?, ImmutableSet<T>> toImmutableSet(); static Collector<T, ?, ImmutableSortedSet<T>> toNaturalImmutableSortedSet(); static Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
			Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper); }
Gullectors { public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { Supplier<ImmutableMap.Builder<K, V>> supplier = ImmutableMap.Builder::new; BiConsumer<ImmutableMap.Builder<K, V>, T> accumulator = (b, t) -> b.put(keyMapper.apply(t), valueMapper.apply(t)); BinaryOperator<ImmutableMap.Builder<K, V>> combiner = (l, r) -> l.putAll(r.build()); Function<ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> finisher = ImmutableMap.Builder::build; return Collector.of(supplier, accumulator, combiner, finisher); }  static Collector<T, ?, ImmutableList<T>> toImmutableList(); static Collector<T, ?, ImmutableSet<T>> toImmutableSet(); static Collector<T, ?, ImmutableSortedSet<T>> toNaturalImmutableSortedSet(); static Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
			Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper);  }