code: static Iterator<Map<Integer, List<Data>>> toBatches(final Iterator<Entry<Integer, Data>> entries,
                                                          final int maxBatch) {
          return new UnmodifiableIterator<Map<Integer, List<Data>>>() {
              @Override
              public boolean hasNext() {
                  return entries.hasNext();
              }
  
              @Override
              public Map<Integer, List<Data>> next() {
                  if (!entries.hasNext()) {
                      throw new NoSuchElementException();
                  }
                  return nextBatch(entries, maxBatch);
              }
          };
      }
docs: Transforms an iterator of entries to an iterator of entry batches
  where each batch is represented as a map from entry key to
  list of entry values.
  The maximum size of the entry value list in any batch is
  determined by the {@code maxBatch} parameter. Only one
  entry value list may have the {@code maxBatch} size, other
  lists will be smaller.
  
  @param entries  the entries to be batched
  @param maxBatch the maximum size of an entry group in a single batch
  @return an iterator with entry batches