|
@@ -2,10 +2,13 @@ package com.zipcodewilmington.streams;
|
2
|
2
|
|
3
|
3
|
import com.zipcodewilmington.streams.anthropoid.Person;
|
4
|
4
|
import com.zipcodewilmington.streams.anthropoid.PersonFactory;
|
|
5
|
+import com.zipcodewilmington.streams.anthropoid.PersonWarehouse;
|
5
|
6
|
import com.zipcodewilmington.streams.tools.RandomUtils;
|
6
|
7
|
import com.zipcodewilmington.streams.tools.StringUtils;
|
7
|
8
|
|
|
9
|
+import java.util.Arrays;
|
8
|
10
|
import java.util.List;
|
|
11
|
+import java.util.Random;
|
9
|
12
|
import java.util.stream.Collectors;
|
10
|
13
|
import java.util.stream.Stream;
|
11
|
14
|
|
|
@@ -16,11 +19,12 @@ public class StreamFilter {
|
16
|
19
|
private final Stream<Person> personStream;
|
17
|
20
|
public final String startingCharacter;
|
18
|
21
|
|
|
22
|
+
|
19
|
23
|
/**
|
20
|
24
|
* No arg constructor
|
21
|
25
|
*/ //TODO - construct person stream of 100 person objects; startingCharacter is a random capital letter
|
22
|
26
|
public StreamFilter() {
|
23
|
|
- this(Stream.empty(), null);
|
|
27
|
+ this(PersonFactory.createPersonArray(100), RandomUtils.createCharacter('A', 'Z'));
|
24
|
28
|
}
|
25
|
29
|
|
26
|
30
|
/**
|
|
@@ -28,7 +32,7 @@ public class StreamFilter {
|
28
|
32
|
* @param startingCharacter - character to filter by
|
29
|
33
|
*/ //TODO
|
30
|
34
|
public StreamFilter(Person[] people, Character startingCharacter) {
|
31
|
|
- this(Stream.empty(), null);
|
|
35
|
+ this(Arrays.asList(people), startingCharacter);
|
32
|
36
|
}
|
33
|
37
|
|
34
|
38
|
/**
|
|
@@ -36,7 +40,7 @@ public class StreamFilter {
|
36
|
40
|
* @param startingCharacter - character to filter by
|
37
|
41
|
*/ //TODO
|
38
|
42
|
public StreamFilter(List<Person> people, Character startingCharacter) {
|
39
|
|
- this(Stream.empty(), null);
|
|
43
|
+ this(people.stream(), startingCharacter);
|
40
|
44
|
}
|
41
|
45
|
|
42
|
46
|
|
|
@@ -55,7 +59,10 @@ public class StreamFilter {
|
55
|
59
|
* @return a list of person object whose name starts with `this.startingCharacter`
|
56
|
60
|
*/ //TODO
|
57
|
61
|
public List<Person> toListMultiLine() {
|
58
|
|
- return null;
|
|
62
|
+ return personStream.filter(p -> {
|
|
63
|
+ return p.getName().startsWith(startingCharacter);
|
|
64
|
+ })
|
|
65
|
+ .collect(Collectors.toList());
|
59
|
66
|
}
|
60
|
67
|
|
61
|
68
|
|
|
@@ -64,7 +71,7 @@ public class StreamFilter {
|
64
|
71
|
* @return a list of person objects whose name starts with `this.startingCharacter`
|
65
|
72
|
*/ //TODO
|
66
|
73
|
public List<Person> toListOneLine() {
|
67
|
|
- return null;
|
|
74
|
+ return personStream.filter(p -> (p.getName().startsWith(startingCharacter))).collect(Collectors.toList());
|
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
|
+ List<Person> filteredList = toListOneLine();
|
|
84
|
+ return filteredList.toArray(new Person[filteredList.size()]);
|
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
|
+ List<Person> filteredList = toListOneLine();
|
|
94
|
+ return filteredList.toArray(new Person[filteredList.size()]);
|
86
|
95
|
}
|
87
|
96
|
|
88
|
97
|
}
|