小编can*_*ble的帖子

流内不同数字类型的转换/比较

我再次遇到Stream API的问题.我试图实现的功能并不是最困难的事情,但由于存在不兼容的类型而我无法过滤,因此我不知道如何使比较正确.这个想法是获取有关给定部分链接到的部门的信息.

department.getSectionId()返回Longwhile Section::getIdInteger(我无法更改)

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());
}
Run Code Online (Sandbox Code Playgroud)

当然,主谓词的结果总是错误的.我知道代码很糟糕,而且我没有正确定义条件,但我希望你能得到这个想法.也许有可能以某种方式合并这些集合或以聪明的方式进行比较.

先感谢您!

java collections java-stream

4
推荐指数
1
解决办法
84
查看次数

标签 统计

collections ×1

java ×1

java-stream ×1