在执行java.lang.IllegalStateException: stream has already been operated upon or closed
时获取findFirst()
。有人知道为什么吗?
public ResultCode getCodeBySourceTypeScope(final List<CodeResult> results,
final String source, final String type,
final String scope) {
if (results.isEmpty()){
return null;
}
final Stream<ResultCode> resultStream = results
.get(0)
.getCodes()
.stream();
if(source != null){
resultStream.filter(code -> code.getSource().equals(source));
}
if(type != null){
resultStream.filter(code -> code.getType().equals(type));
}
if(scope != null){
resultStream.filter(code -> String.valueOf(code.getScope()).equals(scope));
}
return resultStream
.findFirst()
.orElse(null);
}