June 2018
Beginner
722 pages
18h 47m
English
This is an interface that represents a Boolean-valued function that has a single method: boolean test(T). Here is an example of a method that creates a Predicate<Integer> function:
Predicate<Integer> createTestSmallerThan(int num){ Predicate<Integer> func = new Predicate<Integer>() { public boolean test(Integer d) { return d < num; } }; return func;}
We can use it to add some logic to the processing method:
void supplyDecideProcessAndConsume(Supplier<Integer> input, Predicate<Integer> test, Function<Integer, Double> process, Consumer<Double> consume){ int in = input.get(); if(test.test(in)){ consume.accept(process.apply(in)); } else { System.out.println("Input " + in + " does not pass the test and not processed."); }}
And ...
Read now
Unlock full access