1111import java .util .List ;
1212import java .util .concurrent .atomic .AtomicInteger ;
1313import java .util .function .Function ;
14+ import java .util .function .Predicate ;
1415import java .util .stream .Collectors ;
1516import java .util .stream .Stream ;
1617
1718import static com .github .lokic .javaplus .join .Join .on ;
18- import static com .github .lokic .javaplus .stream .ExStream .Func .*;
19+ import static com .github .lokic .javaplus .stream .ExStreamTest .Func .*;
1920
2021public class ExStreamTest {
2122
@@ -62,14 +63,14 @@ public void func_filter() {
6263 Assert .assertEquals (Lists .newArrayList ("1" , "3" ), li );
6364 }
6465
65- // @Test
66- // public void test_filter() {
67- // List<String> li = ExStream.of(Stream.of("1", "2", "3"))
68- // .filter(x -> !"2".equals(x))
69- // .stream()
70- // .collect(Collectors.toList());
71- // Assert.assertEquals(Lists.newArrayList("1", "3"), li);
72- // }
66+ @ Test
67+ public void test_filter () {
68+ List <String > li = ExStream .of (Stream .of ("1" , "2" , "3" ))
69+ .filter (x -> !"2" .equals (x ))
70+ .stream ()
71+ .collect (Collectors .toList ());
72+ Assert .assertEquals (Lists .newArrayList ("1" , "3" ), li );
73+ }
7374
7475 @ Test
7576 public void test_map () {
@@ -80,15 +81,14 @@ public void test_map() {
8081 Assert .assertEquals (Lists .newArrayList ("A1" , "A2" , "A3" ), li );
8182 }
8283
83- //
84- // @Test
85- // public void func_map() {
86- // List<String> li = ExStream.of(Stream.of("1", "2", "3"))
87- // .map(x -> "A" + x)
88- // .stream()
89- // .collect(Collectors.toList());
90- // Assert.assertEquals(Lists.newArrayList("A1", "A2", "A3"), li);
91- // }
84+ @ Test
85+ public void func_map () {
86+ List <String > li = ExStream .of (Stream .of ("1" , "2" , "3" ))
87+ .map (x -> "A" + x )
88+ .stream ()
89+ .collect (Collectors .toList ());
90+ Assert .assertEquals (Lists .newArrayList ("A1" , "A2" , "A3" ), li );
91+ }
9292
9393 @ Test
9494 public void func_flatMap () {
@@ -99,15 +99,15 @@ public void func_flatMap() {
9999 Assert .assertEquals (Lists .newArrayList ("A1" , "A2" , "A3" ), li );
100100 }
101101
102- //
103- // @Test
104- // public void test_flatMap() {
105- // List<String> li = ExStream.of(Stream.of("1", "2", "3"))
106- // .flatMap(x -> Stream.of("A" + x))
107- // .stream()
108- // .collect(Collectors.toList());
109- // Assert.assertEquals(Lists.newArrayList("A1", "A2", "A3"), li);
110- // }
102+
103+ @ Test
104+ public void test_flatMap () {
105+ List <String > li = ExStream .of (Stream .of ("1" , "2" , "3" ))
106+ .flatMap (x -> Stream .of ("A" + x ))
107+ .stream ()
108+ .collect (Collectors .toList ());
109+ Assert .assertEquals (Lists .newArrayList ("A1" , "A2" , "A3" ), li );
110+ }
111111
112112 @ Test
113113 public void takeWhile () {
@@ -216,4 +216,18 @@ public String convert(Integer x) {
216216 }
217217 }
218218
219+ public static class Func {
220+ public static <T > Function <Stream <T >, Stream <T >> filter (Predicate <? super T > predicate ) {
221+ return s -> s .filter (predicate );
222+ }
223+
224+ public static <T , R > Function <Stream <T >, Stream <R >> map (Function <? super T , ? extends R > mapper ) {
225+ return s -> s .map (mapper );
226+ }
227+
228+ public static <T , R > Function <Stream <T >, Stream <R >> flatMap (Function <? super T , ? extends Stream <? extends R >> mapper ) {
229+ return s -> s .flatMap (mapper );
230+ }
231+ }
232+
219233}
0 commit comments