看起来像这应该是Stream.of一些简单的使用方式,但....
这是我想要改进的代码(myEntryIds是Long几千个项目的长度列表):
List<MyEntityType> results = new ArrayList<>();
// batch up into groups of 1000
for (final List<Long> partitionedEntryIds :
com.google.common.collect.Iterables.partition(myEntryIds, 1000)) {
results.addAll(BeanConverter.convertList(
myJpaRepository.findAll(partitionedEntryIds)));
}
return results;
Run Code Online (Sandbox Code Playgroud)
Iterables#partition在JDK流中没有等价物,但您可以使用Guava的Streams#stream帮助toImmutableList()器和收集器(以及我个人喜欢的一些方法引用)来实现您的其他目标:
final List<MyEntityType> myEntityTypes = Streams.stream(
Iterables.partition(myEntryIds, 1000))
.map(myJpaRepository::findAll)
.map(BeanConverter::convertList)
.flatMap(List::stream)
.collect(toImmutableList());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |