Streams and assertion libraries. (Using APIs).
1. Streaming Persons
In the sheets you find a variant of the code below
print rhymes with
aal
void method() {
List<Person> personList = new ArrayList<>();
personList.add(new Person("John Doe", 15));
personList.add(new Person("Jane Doe", 17));
personList.add(new Person("Anne Modaal", 35));
personList.add(new Person("Max Modaal", 19));
personList.add(new Person("Tom Generaal", 53));
personList.add(new Person("Erika Modaal", 28));
personList
.stream() (1)
.map(Person::getName) (2)
.map(String::toLowerCase) (3)
.filter(s -> s.endsWith("aal")) (4)
.forEach(System.out::println); (5)
}
1 | Stream the collection. |
2 | turn it into a stream of names |
3 | make it lower. You could combine 2 and 3. |
4 | select only the ones matching |
5 | pull the stream (terminal op) and print each that comes out. |
Question. What is the stream Type after 1 and what after 2?
Make a version that computes the average age of the daals. (If you did not guess it yet: the numbers are the ages.).
Use streams of course.
2. CSV2Objects
3. Lambda Library
The start project is a maven project for easy integration of the test framework AssertJ.