使用Java Stream流优化后的代码如下所示:

private List checkSpecial(final String templateVersionId, final String empCode) { // 特殊人员处理 final WorkProbitySpecialIdentityDTO specialIdentityDTO = evaluationParamService.getWorkProbitySpecialIdentity( templateVersionId); if (Objects.isNull(specialIdentityDTO)) { return Collections.emptyList(); }

List<EvaluationAnnexFileNameEnum> result = Stream.concat(
        specialIdentityDTO.getOneLevelPrincipals().stream().map(SimpleEmployeeDTO::getCode),
        specialIdentityDTO.getOneLevelDeputys().stream().map(SimpleEmployeeDTO::getCode))
    .filter(item -> StringUtils.equals(item, empCode))
    .map(item -> {
        if (specialIdentityDTO.getOneLevelPrincipals().stream().anyMatch(principal -> StringUtils.equals(principal.getCode(), empCode))) {
            return PRINCIPALS_UPLOAD_FILE_TYPES;
        } else if (specialIdentityDTO.getOneLevelDeputys().stream().anyMatch(deputy -> StringUtils.equals(deputy.getCode(), empCode))) {
            return DEPUTY_UPLOAD_FILE_TYPES;
        } else {
            return null;
        }
    })
    .filter(Objects::nonNull)
    .findFirst()
    .orElse(Collections.emptyList());

return result;
使用Java Stream流优化下面的代码需要去除过多的ifprivate ListEvaluationAnnexFileNameEnum checkSpecialfinal String templateVersionId final String empCode 特殊人员处理 final WorkProbitySpecialIdentityDTO special

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

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