CollectionUtils { public static <T> List<List<T>> group( Collection<T> input, int groupSize ) { return group( input, groupSize, true ); }  static int count( List<T> list, T value ); static void filter( Collection<V> input, Predicate<V> predicate ); static void startsWith( Collection<V> input, final String prefix ); static ImmutableList<V> startingWith( Collection<V> input, final String prefix  ); static List<T> shuffle( List<T> list ); static List<List<T>> group( Collection<T> input, int groupSize ); static List<List<T>> group( Collection<T> input, int groupSize, boolean partial ); static T first( Collection<T> input ); @Nullable static T last( Collection<T> input ); static List<T> head( Collection<T> input, int count ); static List<T> tail( Collection<T> input, int count ); static List<T> sort( Collection<T> input ); static List<T> sort( Collection<T> input, Comparator<T> comparator ); static List<String> strings( Collection<T> input ); static ImmutableList<String> toStrings( Collection<T> input ); static List<T> trim(List<T> list, int count);  }
@Test public void testGroup() throws Exception { assertEquals( "[]", group( Lists.newArrayList(), 2, true ).toString() ); assertEquals( "[]", group( Lists.newArrayList( 1 ), 2, false ).toString() ); assertEquals( "[[1, 2], [3, 4], [5]]", group( Lists.newArrayList( 1, 2, 3, 4, 5 ), 2, true ).toString() ); assertEquals( "[[1, 2], [3, 4]]", group( Lists.newArrayList( 1, 2, 3, 4, 5 ), 2, false ).toString() ); }