优化以下代码: FileMatrixVo fileMatrixVo = new FileMatrixVo(); fileMatrixVo.setId(tableName + "-" + columnName); fileMatrixVo.setCoherenceFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.ENUMERATION_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setEffectiveFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.REGEXP_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setCompleteFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.NULL_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setUniquenessFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.UNIQUENESS_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setMultiTableConsistency(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.MULTI_TABLE_ACCURACY.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setFieldLengthFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.FIELD_LENGTH_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setTimelinessFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.TIMELINESS_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList()));
时间: 2024-03-10 13:44:00 浏览: 76
可以将重复的代码抽取到一个方法中,减少代码冗余,如下:
```
private List<ErrorOutputFileVo> filterErrorOutputFiles(List<ErrorOutputFileVo> errorOutputFiles, String ruleTemplateId) {
return errorOutputFiles.stream()
.filter(errorOutputFileVo -> ruleTemplateId.equals(errorOutputFileVo.getRuleTemplateId()))
.collect(Collectors.toList());
}
...
FileMatrixVo fileMatrixVo = new FileMatrixVo();
fileMatrixVo.setId(tableName + "-" + columnName);
fileMatrixVo.setCoherenceFiles(filterErrorOutputFiles(errorOutputFiles, RuleTemplateName.ENUMERATION_CHECK.getId()));
fileMatrixVo.setEffectiveFiles(filterErrorOutputFiles(errorOutputFiles, RuleTemplateName.REGEXP_CHECK.getId()));
fileMatrixVo.setCompleteFiles(filterErrorOutputFiles(errorOutputFiles, RuleTemplateName.NULL_CHECK.getId()));
fileMatrixVo.setUniquenessFiles(filterErrorOutputFiles(errorOutputFiles, RuleTemplateName.UNIQUENESS_CHECK.getId()));
fileMatrixVo.setMultiTableConsistency(filterErrorOutputFiles(errorOutputFiles, RuleTemplateName.MULTI_TABLE_ACCURACY.getId()));
fileMatrixVo.setFieldLengthFiles(filterErrorOutputFiles(errorOutputFiles, RuleTemplateName.FIELD_LENGTH_CHECK.getId()));
fileMatrixVo.setTimelinessFiles(filterErrorOutputFiles(errorOutputFiles, RuleTemplateName.TIMELINESS_CHECK.getId()));
```
阅读全文