All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.utils.IterableUtils Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
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