IterableUtils { public static <K> int size(final Iterable<? extends K> iterable) { checkNotNull(iterable); if (iterable instanceof Collection) { return ((Collection) iterable).size(); } else { int size = 0; final Iterator iterator = iterable.iterator(); while (iterator.hasNext()) { ++size; iterator.next(); } return size; } } private  IterableUtils(); static boolean isEmpty(final Iterable<? super K> iterable); static List<K> listCopy(final Iterable<? extends K> iterable); static List<K> sortedListCopy(final Iterable<? extends K> iterable); static List<K> sortedReversedListCopy(final Iterable<? extends K> iterable); static List<K> sortedListCopy(final Iterable<? extends K> iterable,
                                             final Comparator<? super K> comparator); static List<K> sortedReversedListCopy(final Iterable<? extends K> iterable,
                                                     final Comparator<? super K> comparator); static int size(final Iterable<? extends K> iterable);  }
@Test public void testSize() throws Exception { final int size = IterableUtils.size(iterable); assertThat(size, is(3)); }
@Test public void testSizeFromCollection() throws Exception { final int size = IterableUtils.size(newArrayList(iterable)); assertThat(size, is(3)); }
@Test public void testSizeFromIterableNotCollection() throws Exception { final int size = IterableUtils.size(new IterableNotCollection()); assertThat(size, is(3)); }