2018-02-08

2018-02-08  本文已影响0人  hothome99

package com.richard.lambdaexpressions;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public class Roster4 {
public static void processPersonsWithFunction(
List<Person> roster,
Predicate<Person> tester,
Consumer<Person> block0,
Function<Person,String> mapper,
Consumer<String> block1){
for(Person p:roster){
if(tester.test(p)){
block0.accept(p);
String data= mapper.apply(p);
block1.accept(data);
}
}
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    List<Person> roster=Person.createRoster();
    processPersonsWithFunction(
            roster,
            p->p.getGender()==Person.Sex.MALE &&
            p.getAge()>=20 &&
            p.getAge()<=45,
            p->p.printPerson(),
            p->p.getEmailAddress(),
            email->System.out.println(email));
}

}

上一篇下一篇

猜你喜欢

热点阅读