/** * Wrap a collection in an object stream. * * The iterator may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param collection A collection to wrap * @return An object stream returning the elements of the collection. */ public static <T> ObjectStream<T> wrap(Collection<? extends T> collection) { return new IteratorObjectStream<>(collection); }
/** * Wrap an iterator in an object stream. * * The iterator may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param iterator An iterator to wrap * @return An object stream returning the elements of the iterator. */ public static <T> ObjectStream<T> wrap(Iterator<? extends T> iterator) { return new IteratorObjectStream<>(iterator); }
/** * Wrap a Java stream in an object stream. * * The stream may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param stream A stream to wrap * @return An object stream returning the elements of the stream. */ public static <T> ObjectStream<T> wrap(Stream<? extends T> stream) { return new IteratorObjectStream<>(stream.iterator()); }
/** * Wrap a Java stream in an object stream. * * The stream may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param stream A stream to wrap * @param root The 'root stream', which will be closed when the resulting stream is closed. * @return An object stream returning the elements of the stream. */ public static <T> ObjectStream<T> wrap(Stream<? extends T> stream, @WillCloseWhenClosed Closeable root) { return new IteratorObjectStream<>(stream.iterator(), root); }
/** * Wrap an iterator in an object stream. * * The iterator may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param iterator An iterator to wrap * @return An object stream returning the elements of the iterator. */ public static <T> ObjectStream<T> wrap(Iterator<? extends T> iterator) { return new IteratorObjectStream<>(iterator); }
/** * Wrap a collection in an object stream. * * The iterator may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param collection A collection to wrap * @return An object stream returning the elements of the collection. */ public static <T> ObjectStream<T> wrap(Collection<? extends T> collection) { return new IteratorObjectStream<>(collection); }
/** * Wrap a Java stream in an object stream. * * The stream may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param stream A stream to wrap * @return An object stream returning the elements of the stream. */ public static <T> ObjectStream<T> wrap(Stream<? extends T> stream) { return new IteratorObjectStream<>(stream.iterator()); }
/** * Wrap a Java stream in an object stream. * * The stream may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param stream A stream to wrap * @param root The 'root stream', which will be closed when the resulting stream is closed. * @return An object stream returning the elements of the stream. */ public static <T> ObjectStream<T> wrap(Stream<? extends T> stream, @WillCloseWhenClosed Closeable root) { return new IteratorObjectStream<>(stream.iterator(), root); }