【发布时间】:2019-03-19 11:23:27
【问题描述】:
我有一个方法 params 是一个大于 50000 个项目的列表; 受限于业务逻辑,列表必须小于30000,这样我才有办法在逻辑之前把这个数组拆分成二维数组
public static final <T> Collection<List<T>> partitionBasedOnSize(List<T> inputList, int size) {
AtomicInteger counter = new AtomicInteger(0);
return inputList.stream().collect(Collectors.groupingBy(s -> counter.getAndIncrement() / size)).values();
}
这是我目前的解决方案:
public List<Account> getChildrenList(List<Long> ids) {
List<Account> childrenList = new ArrayList<>();
Collection<List<Long>> childrenId2dList = PartitionArray.partitionBasedOnSize(childrenIdsList, 30000);
for (List<Long> list : childrenId2dList) {
//this is my business logic: start
childrenList.addAll(accountRepository.getAccounts(list));
//this is my business logic: end
}
return childrenAccountsList;
}
我想在方法之上创建一个注释而不是许多重复的代码(每次都检查和尽管...)
【问题讨论】:
标签: java java-8 java-annotations