Package dev.enola.common.collect
Class MoreIterables
java.lang.Object
dev.enola.common.collect.MoreIterables
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,E extends Exception>
voidforEach(Iterable<T> iterable, CheckedConsumer<T, E> action) static OptionalIntsizeIfKnown(Iterable<?> iterable) Size of anIterable, if there is an efficient way of obtaining it.static <T> Collection<T> toCollection(Iterable<T> iterable) Convert anIterableto aCollection.
-
Method Details
-
forEach
public static <T,E extends Exception> void forEach(Iterable<T> iterable, CheckedConsumer<T, E> action) throws E- Throws:
E
-
sizeIfKnown
Size of anIterable, if there is an efficient way of obtaining it. Useful for optimizations. See alsoIterables.size(Iterable). -
toCollection
Convert anIterableto aCollection.- Type Parameters:
T- Type- Parameters:
iterable- anIterable(of any kind)- Returns:
- Collection which may just be the argument if that
Iterablewas a Collection already (as an optimization), or otherwise anImmutableList. 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.
-