我可以简化此代码还是重写使用Stream?我认为这是可能的,但我不知道如何实现。谢谢大家!
@Override
public List transformList(List list) {
List<QuestionDto> questionDtoList = (List<QuestionDto>) list;
Set<QuestionDto> resultSet = new HashSet<>();
for (QuestionDto question : questionDtoList) {
Set<TagDto> setTag = new HashSet<>();
for (QuestionDto question1 : questionDtoList) {
if (question.getId().equals(question1.getId())) {
setTag.addAll(question.getTags());
setTag.addAll(question1.getTags());
}
}
List<TagDto> tagDtoList = new ArrayList<>(setTag);
question.setTags(tagDtoList);
resultSet.add(question);
}
return new ArrayList<>(resultSet);
}