1

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?

Aritz
  • 30,971
  • 16
  • 136
  • 217
  • http://stackoverflow.com/questions/32434592/partition-a-java-8-stream/32435407#32435407 and http://stackoverflow.com/questions/34405452/split-hashmap-to-partitions-in-java-8/34407196#34407196 – assylias Jul 29 '16 at 08:51

0 Answers0