I have collection of company and each company has list of department and department which are filtered based on complex multilevel condition. I would like to get the department info from some other source when there is no department found in a company and then proceed with filter condition as next step. Is the below implementation best way to achieve ?
public class Company{ private List<Department> departments; } List<Company> newCompanies = companies.stream().forEach(c -> { if(CollectionUtils.isEmpty(c.getDepartments())){ //handle no department //Set the department after getting from different source } }); newCompaniescompanies.stream() .filter(c -> CollectionUtils.isNotEmpty(c.getDepartments())) .filter(c -> c.getDepartments().stream() .anyMatch(d -> condition)) .collect(Collectors.toList());