@Test(dataProvider = "splitProvider") public void testSplit(List<Integer> list, final int SUBSET_SIZE) { final int EXPECTED_SET_COUNT = (int)Math.ceil((double)list.size() / (double)SUBSET_SIZE); Collection<List<Integer>> splitCollection = CollectionUtil.split(list, SUBSET_SIZE); Assert.assertEquals(splitCollection.size(), EXPECTED_SET_COUNT); }
public static <T> Collection<List<T>> split(Collection<T> collection, final int subsetSize) { if(collection == null || subsetSize < 1) return null; AtomicInteger subsetCounter = new AtomicInteger(); return collection.stream().collect(Collectors.groupingBy(it -> subsetCounter.getAndIncrement() / subsetSize)).values(); }
CollectionUtil { public static <T> Collection<List<T>> split(Collection<T> collection, final int subsetSize) { if(collection == null || subsetSize < 1) return null; AtomicInteger subsetCounter = new AtomicInteger(); return collection.stream().collect(Collectors.groupingBy(it -> subsetCounter.getAndIncrement() / subsetSize)).values(); } }
CollectionUtil { public static <T> Collection<List<T>> split(Collection<T> collection, final int subsetSize) { if(collection == null || subsetSize < 1) return null; AtomicInteger subsetCounter = new AtomicInteger(); return collection.stream().collect(Collectors.groupingBy(it -> subsetCounter.getAndIncrement() / subsetSize)).values(); }  }
CollectionUtil { public static <T> Collection<List<T>> split(Collection<T> collection, final int subsetSize) { if(collection == null || subsetSize < 1) return null; AtomicInteger subsetCounter = new AtomicInteger(); return collection.stream().collect(Collectors.groupingBy(it -> subsetCounter.getAndIncrement() / subsetSize)).values(); }  static Collection<List<T>> split(Collection<T> collection, final int subsetSize); }
CollectionUtil { public static <T> Collection<List<T>> split(Collection<T> collection, final int subsetSize) { if(collection == null || subsetSize < 1) return null; AtomicInteger subsetCounter = new AtomicInteger(); return collection.stream().collect(Collectors.groupingBy(it -> subsetCounter.getAndIncrement() / subsetSize)).values(); }  static Collection<List<T>> split(Collection<T> collection, final int subsetSize);  }