/** * Groups entries by the entry key. The entries will be grouped * until at least one group has up to {@code maxBatch} * entries or until the {@code entries} have been exhausted. * * @param entries the entries to be grouped by key * @param maxBatch the maximum size of a group * @return the grouped entries by entry key */ private static Map<Integer, List<Data>> nextBatch(Iterator<Entry<Integer, Data>> entries, int maxBatch) { Map<Integer, List<Data>> batch = createHashMap(maxBatch); while (entries.hasNext()) { Entry<Integer, Data> e = entries.next(); List<Data> partitionKeys = CollectionUtil.addToValueList(batch, e.getKey(), e.getValue()); if (partitionKeys.size() >= maxBatch) { break; } } return batch; }
/** * Groups entries by the entry key. The entries will be grouped * until at least one group has up to {@code maxBatch} * entries or until the {@code entries} have been exhausted. * * @param entries the entries to be grouped by key * @param maxBatch the maximum size of a group * @return the grouped entries by entry key */ private static Map<Integer, List<Data>> nextBatch(Iterator<Entry<Integer, Data>> entries, int maxBatch) { Map<Integer, List<Data>> batch = createHashMap(maxBatch); while (entries.hasNext()) { Entry<Integer, Data> e = entries.next(); List<Data> partitionKeys = CollectionUtil.addToValueList(batch, e.getKey(), e.getValue()); if (partitionKeys.size() >= maxBatch) { break; } } return batch; }