Class MoreIterables

java.lang.Object
dev.enola.common.collect.MoreIterables

public final class MoreIterables extends Object
  • Method Details

    • forEach

      public static <T, E extends Exception> void forEach(Iterable<T> iterable, CheckedConsumer<T,E> action) throws E
      Throws:
      E
    • sizeIfKnown

      public static OptionalInt sizeIfKnown(Iterable<?> iterable)
      Size of an Iterable, if there is an efficient way of obtaining it. Useful for optimizations. See also Iterables.size(Iterable).
    • toCollection

      public static <T> Collection<T> toCollection(Iterable<T> iterable)
      Convert an Iterable to a Collection.
      Type Parameters:
      T - Type
      Parameters:
      iterable - an Iterable (of any kind)
      Returns:
      Collection which may just be the argument if that Iterable was a Collection already (as an optimization), or otherwise an ImmutableList. Note that this means that callers should always assume that the returned collection is logically immutable. Due to the optimization for Iterables that are Collections, we just cannot (efficiently) actually declare the return type to be an ImmutableCollection.