I've got a single operation to retrieve a list of elements:
public EquipmentExchangeSet list(Set<Long> ids) {
return restTemplate.getForEntity(equipmentServiceUrl + ids,
EquipmentExchangeSet.class).getBody();
}
Now I want to execute it subsequently making subsets of ids grouping them 1000 by 1000. That's the way I do it using Guava's Iterables#partition
:
public EquipmentExchangeSet list(Set<Long> ids) {
EquipmentExchangeSet result = new EquipmentExchangeSet();
for (List<Long> idSubset : Iterables.partition(ids, 1000)) {
result.addAll(restTemplate
.getForEntity(equipmentServiceUrl + idSubset , EquipmentExchangeSet.class)
.getBody());
}
return result;
}
However, it would be nice to process the id set with Java Streams. Is there a way to process the elements N by N using Java Streams?