今天修改个东西,看到有一段代码被人优化了!!!
优化前
public Optional<List<Map<String, String>>> getByCodesString type, List<String> codeList) {
if codeList.size) <= DEFAULT_PAGE_SIZE) {
return getByBatchtype, codeList);
}
return IntStream.range0, codeList.size) + DEFAULT_PAGE_SIZE - 1) / DEFAULT_PAGE_SIZE)
.mapToObji -> codeList.subListi * DEFAULT_PAGE_SIZE, Math.minDEFAULT_PAGE_SIZE * i + 1), codeList.size))))
.maplist -> getByBatchtype, list).orElsenew ArrayList<>)))
.reducea, b) -> {
a.addAllb);
return a;
});
}
private Optional<List<Map<String, String>>> getByBatchString type, List<String> codeList) {}
优化后
public Optional<List<Map<String, String>>> getByCodesString type, List<String> codeList) {
Optional<List<Map<String, String>>> result = null;
if codeList.size) <= DEFAULT_PAGE_SIZE) {
result = getByBatchtype, codeList);
ifresult.isPresent) && CollectionUtils.isNotEmptyresult.get))){
return result;
}
return Optional.empty);
}
result = IntStream.range0, codeList.size) + DEFAULT_PAGE_SIZE - 1) / DEFAULT_PAGE_SIZE)
.mapToObji -> codeList.subListi * DEFAULT_PAGE_SIZE, Math.minDEFAULT_PAGE_SIZE * i + 1), codeList.size))))
.maplist -> getByBatchtype, list).orElsenew ArrayList<>)))
.reducea, b) -> {
a.addAllb);
return a;
});
ifresult.isPresent) && CollectionUtils.isNotEmptyresult.get))){
return result;
}
return Optional.empty);
}
private Optional<List<Map<String, String>>> getByBatchString type, List<String> codeList) {}