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 filterBasedOnConsistAge(employeeJSONString) &&
filterBasedOnConsistGender(employeeJSONString) &&
filterBasedOnConsistNationality(employeeJSONString) &&
filterBasedOnConsistHandicap(employeeJSONString);
}
private String employeeToString(Employee employee) {
// converts domainObject to a formatted string, it'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?