使用Stream优化代码: 简化中层民主测评数据处理
使用Stream进行代码优化可以简化代码逻辑和提高代码可读性。下面是使用Stream进行优化的代码示例:\n\njava\nfinal List<ExamineEvaluationEntity> evaluationExaminers = midLevelDemocracyEvaluations.stream()\n .skip(1) // 跳过第一行数据\n .peek(currentMiddleEvaluation -> {\n if (StringUtils.isBlank(currentMiddleEvaluation.getAppraiseeName())) {\n setMidLevelEvaluationInfo(standardMiddleEvaluation, currentMiddleEvaluation, templateCode);\n }\n })\n .map(currentMiddleEvaluation -> createEvaluationExaminer(activityId, loginUserPojo, currentMiddleEvaluation, appraiseeEmpCodeMap, examinerEmpMap))\n .collect(Collectors.toList());\n\nreturn evaluationExaminers;\n\n\n这段代码使用stream()方法将midLevelDemocracyEvaluations转换为Stream,然后使用skip(1)跳过第一行数据。接着使用peek()方法判断当前中层民主测评数据对象是否为空,如果为空则将前一条数据的属性设置到当前数据对象。然后使用map()方法创建并添加考核测评数据。最后使用collect()方法将Stream转换为List返回。
原文地址: https://www.cveoy.top/t/topic/qqM0 著作权归作者所有。请勿转载和采集!