我有这样的EmployObject的Java列表
List<Employee> emp = {emp1, emp2, emp3, emp4 ,...}
Where the Employee class looks like this
Public Class Employee {
String EmpId;
EmpInfo empInfo;
}
public class EmpInfo {
String salary;
String address;
List<Reviews> reviews;
}
public class Reviews {
int ratings;
boolean isGood;
}
我想使用Java8流来遍历列表(List emp)并过滤EmpId,该EmpId具有多个评分(List lenghth> 1),并且其评分很好(isGood == true)。新列表看起来像
List empRating = {empRating1,empRating2,...}
public class EmpRating {
String empId;
int ratings;
}
我尝试了不同的方法,但无法找到优化的解决方案。需要帮助。
仅举一个例子:
isGood
的员工employeeList.stream()
.filter(emp -> emp.getEmpInfo().getReviews().size() > 1
&& emp.getEmpInfo().getReviews().stream().anyMatch(Reviews::isGood))
.map(emp -> new EmpRating(
emp.getEmpId(),
emp.getEmpInfo().getReviews().stream().mapToInt(Reviews::getRatings).sum()
))
.collect(Collectors.toList());