I'm having a problem with Stream API... again. The functionality I'm trying to implement isn't the hardest thing, but I'm having difficulties filtering since there are incompatible types and I don't how to make the comparison right. The idea is to get information about departments which the given sections are linked to.
department.getSectionId() returns Long while Section::getId is an Integer (which I can't change)
private List<DepartmentInfo> retrieveLinkedDepartments(final Collection<Section> sections) {
return this.departmentDao
.findAll()
.stream()
.filter(department -> department.getSectionId() != null)
.filter(department -> department.getSectionId().equals(sections.stream().map(Section::getId)))
.map(this.departmentInfoMapper::map)
.collect(Collectors.toList());
}
Of course the result of the main predicate is always false. I know the code is awful and I'm not defining conditions right, but I hope you get the idea. Maybe there's a possibility to somehow merge these collections or compare in a smart way.
Thank you in advance!