public FlowCollectAndSortWithComparator<B, List<B>> toSortedList(Comparator<? super B> comparator) { return toSortedList(new ArrayList<B>(), comparator); }
public FlowCollectAndSort<B, List<B>> toSortedList() { return toSortedList(new ArrayList<B>()); }
public FlowCollectAndSortWithComparator<B, List<B>> toSortedList(Comparator<? super B> comparator) { return toSortedList(new ArrayList<B>(), comparator); }
public FlowCollectAndSort<B, List<B>> toSortedList() { return toSortedList(new ArrayList<B>()); }
@Test public void test_sorted_list() { List<Integer> result = Flow.of(3, 2, 1).toSortedList().get(); Assert.assertEquals(3, result.size()); Assert.assertEquals(Integer.valueOf(1), result.get(0)); Assert.assertEquals(Integer.valueOf(2), result.get(1)); Assert.assertEquals(Integer.valueOf(3), result.get(2)); }
@Test public void test_grouping_1() { List<ArrayList<Integer>> result = Flow.of(1, 2, 3) .groupBy(new Mapper<Integer, Boolean>() { @Override public Boolean map(Integer it) { return it % 2 == 0; } }) .flatMap(new Mapper<FlowGroup<Boolean, Integer>, FlowProcessOnEnd<?, ArrayList<Integer>>>() { @Override public FlowProcessOnEnd<?, ArrayList<Integer>> map(FlowGroup<Boolean, Integer> group) { return group.toList(); } }) .toSortedList(new Comparator<List<Integer>>() { @Override public int compare(List<Integer> o1, List<Integer> o2) { return o1.size() < o2.size() ? -1 : (o1.size() == o2.size() ? 0 : 1); } }).get(); Assert.assertEquals(2, result.size()); Assert.assertEquals(1, result.get(0).size()); Assert.assertEquals(Integer.valueOf(2), result.get(0).get(0)); Assert.assertEquals(2, result.get(1).size()); Assert.assertEquals(Integer.valueOf(1), result.get(1).get(0)); Assert.assertEquals(Integer.valueOf(3), result.get(1).get(1)); }
@Test public void test_grouping_3() { List<Integer> result = Flow.of(1, 2, 3) .groupBy(new Mapper<Integer, Boolean>() { @Override public Boolean map(Integer it) { return it % 2 == 0; } }) .flatMap(new Mapper<FlowGroup<Boolean, Integer>, FlowProcessOnEnd<?, Integer>>() { @Override public FlowProcessOnEnd<?, Integer> map(FlowGroup<Boolean, Integer> group) { return group.first(); } }) .toSortedList() .get(); Assert.assertEquals(2, result.size()); Assert.assertEquals(Integer.valueOf(1), result.get(0)); Assert.assertEquals(Integer.valueOf(2), result.get(1)); }
.toSortedList(new Comparator<List<Integer>>() { @Override public int compare(List<Integer> o1, List<Integer> o2) {