Predicate Interface
The predicate interface is a quite simple, yet surprisingly elegant and complex, functional interface that allows you, as a programmer, to define functions that describe the state of your program in the shape of Booleans. In Java, speech predicates are one-argument functions that return a Boolean value.
The predicate API looks like this:
boolean test(T t);
However, the predicate API also utilizes the new interface features of Java 8. It supports default and static functions to enrich the API, allowing more complex descriptions of your program's state. Here, three functions are important:
Predicate<T> and(Predicate<T>); Predicate<T> or(Predicate<T>); Predicate<T> not(Predicate<T>);
With these three functions, you can chain predicates to describe more complex queries on your program's state. The and
function will combine two or more predicates, ensuring that every predicate supplied returns true.
The...