io.sphere.sdk.utils.IterableUtils Maven / Gradle / Ivy
package io.sphere.sdk.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Stream;
public final class IterableUtils {
private IterableUtils() {
}
public static boolean isEmpty(final Iterable> iterable) {
return !iterable.iterator().hasNext();
}
public static Iterable requireNonEmpty(final Iterable iterable) {
if (isEmpty(iterable)) {
throw new IllegalArgumentException("iterable must not be empty.");
}
return iterable;
}
public static List toList(final Iterable iterable) {
List list = new ArrayList<>();
for (final T item : iterable) {
list.add(item);
}
return list;
}
public static Stream toStream(final Iterable iterable) {
return toList(iterable).stream();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy