code: private static <E> Collection<E> castOrCopyToCollection(Iterable<E> iterable) {
      return (iterable instanceof Collection)
          ? (Collection<E>) iterable
          : Lists.newArrayList(iterable.iterator());
    }
docs: Converts an iterable into a collection. If the iterable is already a collection, it is
  returned. Otherwise, an {@link java.util.ArrayList} is created with the contents of the
  iterable in the same iteration order.