I have the following map of the search criteria:
private final Map<String, Predicate> searchMap = new HashMap<>();
private void initSearchMap() {
Predicate<Person> allDrivers = p -> p.getAge() >= 16;
Predicate<Person> allDraftees = p -> p.getAge() >= 18
&& p.getAge() <= 25
&& p.getGender() == Gender.MALE;
Predicate<Person> allPilots = p -> p.getAge() >= 23
&& p.getAge() <=65;
searchMap.put("allDrivers", allDrivers);
searchMap.put("allDraftees", allDraftees);
searchMap.put("allPilots", allPilots);
}
I am using this map in the following way:
pl.stream()
.filter(search.getCriteria("allPilots"))
.forEach(p -> {
p.printl(p.getPrintStyle("westernNameAgePhone"));
});
I would like to know, how can I pass some parameters into the map of predicates?
I.e. I would like to get predicate from a map by its string abbreviation and insert a parameter into the taken out from a map predicate.
pl.stream()
.filter(search.getCriteria("allPilots",45, 56))
.forEach(p -> {
p.printl(p.getPrintStyle("westernNameAgePhone"));
});
Here is the link from I googled out this map-predicate approach.
allPilots
i.e. this predicate should return false if the pilot age is not in the age range (45, 65). – Subfusc