
Let the code explain itself..Be quiet...And read..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Predicate<T>-- T in ,boolean out | |
Predicate<Man> richManMatcher = m->m.getCashAmount () > 1000000; | |
if (richManMatcher.test (someMan)) { | |
marryWithRichMan (someMan); | |
} | |
Function<T,R> -- Tin, R out | |
Function<Worker,Integer> salaryIncreaser = w->w.getSalary () + 500; | |
for (Worker worker: workers){ | |
worker.setSalary (salaryIncreaser.apply(worker)); | |
} | |
// OR with Method References | |
workers.stream ().map (salaryIncreaser::apply); | |
BiFunction<T,U,R> -- Tin, R out | |
Worker worker = new Worker ("worker",120,80); | |
List<Worker> workers = new ArrayList<> (); | |
BiFunction<Integer, Integer, Integer> bodyIndexCalculator = (h,w) -> h/w; | |
Integer workerBodyIndex = bodyIndexCalculator.apply (worker.getHeight (), worker.getWeight ()); | |
workers.stream ().mapToInt (w->bodyIndexCalculator.apply (w.getHeight (),w.getWeight ())).average (); | |
Consumer<T> --T in, void | |
Consumer<Worker> salaryIncreaser = w->w.setSalary (w.getSalary () * 1.2); | |
for (Worker worker: workers){ | |
salaryIncreaser.accept(worker)); | |
} | |
Supplier<T> -- Nothing In -- T out | |
Supplier<Worker> hardWorkingWorkerSupplier = ()->randomWorkerFromSomeWhere(); | |
Worker w = hardWorkingWorkerSupplier.get(); | |
BinaryOperator<T> -- TwoT's in, T out | |
BinaryOperator<Integer> multiplier = (n1,n2) ->n1 * n2; | |
int multipliedvalue = multiplier.apply (n1,n2); |
Bye
No comments:
Post a Comment