I have a Predicate which takes employee object.
Predicate<Employee> getPredicate() {
return emp -> filter(emp);
}
Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.
private boolean filter(Employee employee) {
String employeeJSONString = employeeToString(employee);
return filterBasedOnAgefilterBasedOnConsistAge(employeeJSONString) &&
filterBasedOnGenderfilterBasedOnConsistGender(employeeJSONString) &&
filterBasedOnNationalityfilterBasedOnConsistNationality(employeeJSONString) &&
filterBasedOnIsHandicapfilterBasedOnConsistHandicap(employeeJSONString);
}
private String employeeToString(Employee employee) {
// retrieveconverts additionaldomainObject employeeto fieldsa usingformatted employeestring, objectit's a business requirement
}
There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?