package modern.challenge; import java.util.Collection; import java.util.stream.Stream; public final class AsStreams { private AsStreams() { throw new AssertionError("Cannot be instantiated"); } public static Stream elementAsStream(T element) { return Stream.ofNullable(element); } public static Stream collectionAsStreamWithNulls(Collection element) { return Stream.ofNullable(element).flatMap(Collection::stream); } public static Stream collectionAsStreamWithoutNulls(Collection collection) { return collection.stream().flatMap(e -> Stream.ofNullable(e)); } public static Stream collectionAsStream(Collection collection) { return Stream.ofNullable(collection) .flatMap(Collection::stream) .flatMap(Stream::ofNullable); } }