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

private boolean isUserTypeExist(String empCode, UserTypeEnum userType) {
    if (userType == UserTypeEnum.APPRAISEE) {
        return activityAppraiseeService.existByEmpCode(empCode);
    } else if (userType == UserTypeEnum.EXAMINER) {
        return activityExaminerService.existByEmpCode(empCode);
    }
    return false;
使用stream流优化下面代码public ListInteger findIdentitiesfinal String empCode final ListInteger roles = ListsnewArrayList; if activityAppraiseeServiceexistByEmpCodeempCode rolesaddUs

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

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