My pom was changed as follows:
Original codeThe original code looked like this:
Pretty straight forward stuff.
Adding a LambdaThen we received two change requests, that could be resolved by re-using the method above.
But this time, not everyone was required to see the message. In other words, the list of active players needed to be filtered.
Enter the Predicate2.
Let us say the filtering needs to be done, by those who wish to be kept in the loop regarding roleplaying events. These users contain an Ooc (Out-of-Character) flag.
Calling this can be done using a Lambda, like so:
sendWall("[OOC: " + aUser.getName() + "] " + message + "\r\n", p -> p.getOoc());
StreamsTo make things a little more complicated, you can make use of the new Streams3 4 provided in Java 8.
In the example below, I take a stream from the List collection provided by getActivePlayers, filter it by the predicate, and run the writeMessage on each found user. That last one is called a "terminator" as it terminates the stream, i.e. it "does something".
A lot less code than the previous for loop. It seems more complicated, but I guess it just requires me to get used to it.
It also causes me to create another Lambda, as the terminator.
The Old WayIn the old way, calling this method sendWall was done using an inner class, and it looked as follows:
-  JavaTM Tutorials - Lambda Expressions
-  JavaDoc - Interface Predicate<T>
-  JavaTM Tutorials - The Collection Interface
-  Processing Data with Java SE 8 Streams, Part 1