The Predicates
class is a collection of useful methods for working with Predicate
instances. The Predicates
class offers some very helpful methods that should be expected from working with Boolean conditions, chaining Predicate
instances with "and" or "or" conditions, and providing a "not" that evaluates to true if the given Predicate
instance evaluates to false and vice versa. There is also a Predicates.compose
method, but it takes a Predicate
instance and a Function
object and returns Predicate
that evaluates the output from the given Function
object. Let's take a look at some examples so we can get a better understanding of how we can use Predicates
in our code. Before we move on to look at specific examples, let's assume we have the following two instances of Predicates
classes defined (in addition to
PopulationPredicate
defined previously) for our City
object:
public class TemperateClimatePredicate implements Predicate<City> { @Override public...