|
|
@@ -5,6 +5,7 @@ import com.zipcodewilmington.streams.anthropoid.PersonFactory;
|
|
5
|
5
|
import com.zipcodewilmington.streams.tools.RandomUtils;
|
|
6
|
6
|
import com.zipcodewilmington.streams.tools.StringUtils;
|
|
7
|
7
|
|
|
|
8
|
+import java.util.Arrays;
|
|
8
|
9
|
import java.util.List;
|
|
9
|
10
|
import java.util.stream.Collectors;
|
|
10
|
11
|
import java.util.stream.Stream;
|
|
|
@@ -20,7 +21,8 @@ public class StreamFilter {
|
|
20
|
21
|
* No arg constructor
|
|
21
|
22
|
*/ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
|
|
22
|
23
|
public StreamFilter() {
|
|
23
|
|
- this(Stream.empty(), null);
|
|
|
24
|
+ this(PersonFactory.createPersonStream(100), RandomUtils.createCharacter('A', 'Z'));
|
|
|
25
|
+
|
|
24
|
26
|
}
|
|
25
|
27
|
|
|
26
|
28
|
/**
|
|
|
@@ -28,7 +30,8 @@ public class StreamFilter {
|
|
28
|
30
|
* @param startingCharacter - character to filter by
|
|
29
|
31
|
*/ //TODO
|
|
30
|
32
|
public StreamFilter(Person[] people, Character startingCharacter) {
|
|
31
|
|
- this(Stream.empty(), null);
|
|
|
33
|
+ this(Arrays.stream(people), startingCharacter);
|
|
|
34
|
+
|
|
32
|
35
|
}
|
|
33
|
36
|
|
|
34
|
37
|
/**
|
|
|
@@ -36,7 +39,7 @@ public class StreamFilter {
|
|
36
|
39
|
* @param startingCharacter - character to filter by
|
|
37
|
40
|
*/ //TODO
|
|
38
|
41
|
public StreamFilter(List<Person> people, Character startingCharacter) {
|
|
39
|
|
- this(Stream.empty(), null);
|
|
|
42
|
+ this(people.stream(), startingCharacter);
|
|
40
|
43
|
}
|
|
41
|
44
|
|
|
42
|
45
|
|
|
|
@@ -55,7 +58,9 @@ public class StreamFilter {
|
|
55
|
58
|
* @return a list of person object whose name starts with `this.startingCharacter`
|
|
56
|
59
|
*/ //TODO
|
|
57
|
60
|
public List<Person> toListMultiLine() {
|
|
58
|
|
- return null;
|
|
|
61
|
+ List<Person> list = personStream.filter(person -> StringUtils.isPalindromeIgnoreCase(person
|
|
|
62
|
+ .getName())).collect(Collectors.toList());
|
|
|
63
|
+ return list;
|
|
59
|
64
|
}
|
|
60
|
65
|
|
|
61
|
66
|
|
|
|
@@ -64,7 +69,9 @@ public class StreamFilter {
|
|
64
|
69
|
* @return a list of person objects whose name starts with `this.startingCharacter`
|
|
65
|
70
|
*/ //TODO
|
|
66
|
71
|
public List<Person> toListOneLine() {
|
|
67
|
|
- return null;
|
|
|
72
|
+ List<Person> list = personStream.filter(person -> StringUtils.isPalindromeIgnoreCase(person
|
|
|
73
|
+ .getName())).collect(Collectors.toList());
|
|
|
74
|
+ return list;
|
|
68
|
75
|
}
|
|
69
|
76
|
|
|
70
|
77
|
|
|
|
@@ -73,7 +80,8 @@ public class StreamFilter {
|
|
73
|
80
|
* @return an array of person object whose name starts with `this.startingCharacter`
|
|
74
|
81
|
*/ //TODO
|
|
75
|
82
|
public Person[] toArrayOneLine() {
|
|
76
|
|
- return null;
|
|
|
83
|
+ return personStream.filter(person -> StringUtils.isPalindromeIgnoreCase(person.getName())).toArray(Person[]::new);
|
|
|
84
|
+
|
|
77
|
85
|
}
|
|
78
|
86
|
|
|
79
|
87
|
|
|
|
@@ -82,7 +90,8 @@ public class StreamFilter {
|
|
82
|
90
|
* @return an array of person object whose name starts with `this.startingCharacter`
|
|
83
|
91
|
*/ //TODO
|
|
84
|
92
|
public Person[] toArrayMultiLine() {
|
|
85
|
|
- return null;
|
|
|
93
|
+
|
|
|
94
|
+ return personStream.filter(person -> StringUtils.isPalindromeIgnoreCase(person.getName())).toArray(Person[]::new);
|
|
86
|
95
|
}
|
|
87
|
96
|
|
|
88
|
97
|
}
|