Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import static com.google.common.collect.Iterables.partition;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class Main {
    /** Partitions a Map into a Collection of Maps, each of max size n. */
    public static <K, V> ImmutableList<ImmutableMap<K, V>> partitionMap(Map<K, V> map, int size) {
        ImmutableList.Builder<ImmutableMap<K, V>> shards = new ImmutableList.Builder<>();
        for (Iterable<Map.Entry<K, V>> entriesShard : partition(map.entrySet(), size)) {
            shards.add(ImmutableMap.copyOf(entriesShard));
        }
        return shards.build();
    }
}