使用Steam流优化后的代码如下:

public List findIdentities(final String empCode) { return Stream.of(UserTypeEnum.APPRAISEE, UserTypeEnum.EXAMINER) .filter(userType -> userTypeExistByEmpCode(userType, empCode)) .map(UserTypeEnum::getValue) .collect(Collectors.toList()); }

private boolean userTypeExistByEmpCode(UserTypeEnum userType, String empCode) { if (userType == UserTypeEnum.APPRAISEE) { return activityAppraiseeService.existByEmpCode(empCode); } else if (userType == UserTypeEnum.EXAMINER) { return activityExaminerService.existByEmpCode(empCode); } return false;

使用steam流优化下面代码public ListInteger findIdentitiesfinal String empCode final ListInteger roles = ListsnewArrayList; if activityAppraiseeServiceexistByEmpCodeempCode rolesaddUse

原文地址: http://www.cveoy.top/t/topic/hCp5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录