CollectionUtils { public static <T> List<T> trim(List<T> list, int count) { List<T> result = Lists.newArrayList(list); for (int i = 0; i < count && result.size() > 0; i++) { int idx = result.size() - 1; result.remove(idx); } return ImmutableList.copyOf(result); }  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 testTrimWithNoEntries() throws Exception { List<String> list = Lists.newArrayList(); assertEquals("[]", CollectionUtils.trim(list, 2).toString()); }
@Test public void testTrimWithOneEntry() throws Exception { List<String> list = Lists.newArrayList(); list.add("1"); assertEquals("[]", CollectionUtils.trim(list, 2).toString()); }
@Test public void testTrimWithTwoEntries() throws Exception { List<String> list = Lists.newArrayList(); list.add("1"); list.add("2"); assertEquals("[]", CollectionUtils.trim(list, 2).toString()); }
@Test public void testTrimWithThreeEntries() throws Exception { List<String> list = Lists.newArrayList(); list.add("1"); list.add("2"); list.add("3"); assertEquals("[1]", CollectionUtils.trim(list, 2).toString()); }