public FlowToMap<K, List<T>, B> toMap() { return toMap(Flow.<K, T>flowGroupListMapper()); }
public <K, V> FlowToMap<K, V, FlowGroup<K, B>> toMap(Supplier<Map<K, FlowGroup<K, B>>> groupMapSupplier, Mapper<B, K> toKey, Mapper<FlowGroup<K, B>, V> toValue) { return groupBy(toKey, groupMapSupplier).toMap(toValue); }
public FlowToMap<K, List<T>, B> toMap() { return toMap(Flow.<K, T>flowGroupListMapper()); }
public <K, V> FlowToMap<K, V, FlowGroup<K, B>> toMap(Supplier<Map<K, FlowGroup<K, B>>> groupMapSupplier, Mapper<B, K> toKey, Mapper<FlowGroup<K, B>, V> toValue) { return groupBy(toKey, groupMapSupplier).toMap(toValue); }
@Test public void test_toMap_2() { Map<Boolean, List<Integer>> map = Flow.of(1, 2, 3) .groupBy(new Mapper<Integer, Boolean>() { @Override public Boolean map(Integer integer) { return integer % 2 == 0; } }) .toMap() .get(); Assert.assertEquals(2, map.size()); Assert.assertEquals(1, map.get(true).size()); Assert.assertEquals(Integer.valueOf(2), map.get(true).get(0)); Assert.assertEquals(2, map.get(false).size()); Assert.assertEquals(Integer.valueOf(1), map.get(false).get(0)); Assert.assertEquals(Integer.valueOf(3), map.get(false).get(1)); }
.toMap(new Mapper<FlowGroup<Integer, Person>, Map<Long, List<Person>>>() { @Override public Map<Long, List<Person>> map(FlowGroup<Integer, Person> ageGroup) {
@Test public void test_toMap_3() { Map<Boolean, List<Integer>> map = Flow.of(1, 2, 3) .groupBy(new Mapper<Integer, Boolean>() { @Override public Boolean map(Integer integer) { return integer % 2 == 0; } }) .filter(new Filter<FlowGroup<Boolean, Integer>>() { @Override public boolean allow(FlowGroup<Boolean, Integer> group) { return group.getKey(); } }) .toMap() .get(); Assert.assertEquals(1, map.size()); Assert.assertEquals(1, map.get(true).size()); Assert.assertEquals(Integer.valueOf(2), map.get(true).get(0)); }
@Test public void test_limit_3() { Assert.assertEquals("{1=[1], 2=[2], 3=[3]}", Flow.of(1, 2, 3, 4, 5) .groupBy(new Mapper<Integer, Integer>() { @Override public Integer map(Integer integer) { return integer; } }) .limit(3) .toMap() .get() .toString() ); }