@Test public void testDistribute_abcde_on3() { List<Character> list = Lists.charactersOf("abcde"); List<Collection<Character>> distribute = Distributor .distribute(list, 3); assertEquals(3, distribute.size()); assertEquals(Lists.charactersOf("ad"), distribute.get(0)); assertEquals(Lists.charactersOf("be"), distribute.get(1)); assertEquals(Lists.charactersOf("c"), distribute.get(2)); }
public static <T> List<Collection<T>> distribute(Collection<T> in, int size) { List<Collection<T>> result = Lists.newArrayListWithExpectedSize(size); for (int i = 0; i < size; i++) { result.add(Lists.<T> newArrayList()); } int index = 0; for (T t : in) { result.get(index++ % size).add(t); } return result; }
Distributor { public static <T> List<Collection<T>> distribute(Collection<T> in, int size) { List<Collection<T>> result = Lists.newArrayListWithExpectedSize(size); for (int i = 0; i < size; i++) { result.add(Lists.<T> newArrayList()); } int index = 0; for (T t : in) { result.get(index++ % size).add(t); } return result; } }
Distributor { public static <T> List<Collection<T>> distribute(Collection<T> in, int size) { List<Collection<T>> result = Lists.newArrayListWithExpectedSize(size); for (int i = 0; i < size; i++) { result.add(Lists.<T> newArrayList()); } int index = 0; for (T t : in) { result.get(index++ % size).add(t); } return result; } private  Distributor(); }
Distributor { public static <T> List<Collection<T>> distribute(Collection<T> in, int size) { List<Collection<T>> result = Lists.newArrayListWithExpectedSize(size); for (int i = 0; i < size; i++) { result.add(Lists.<T> newArrayList()); } int index = 0; for (T t : in) { result.get(index++ % size).add(t); } return result; } private  Distributor(); static List<Collection<T>> distribute(Collection<T> in, int size); }
Distributor { public static <T> List<Collection<T>> distribute(Collection<T> in, int size) { List<Collection<T>> result = Lists.newArrayListWithExpectedSize(size); for (int i = 0; i < size; i++) { result.add(Lists.<T> newArrayList()); } int index = 0; for (T t : in) { result.get(index++ % size).add(t); } return result; } private  Distributor(); static List<Collection<T>> distribute(Collection<T> in, int size);  }