/** * Returns a sequential {@code StreamEx} containing a single element, if * non-null, otherwise returns an empty {@code StreamEx}. * * @param element the single element * @param <T> the type of stream elements * @return a stream with a single element if the specified element is * non-null, otherwise an empty stream * @since 0.1.1 */ public static <T> StreamEx<T> ofNullable(T element) { return element == null ? empty() : of(element); }
/** * Returns a sequential {@code StreamEx} containing an {@link Optional} * value, if present, otherwise returns an empty {@code StreamEx}. * * @param <T> the type of stream elements * @param optional the optional to create a stream of * @return a stream with an {@code Optional} value if present, otherwise an * empty stream * @since 0.1.1 */ public static <T> StreamEx<T> of(Optional<? extends T> optional) { return optional.isPresent() ? of(optional.get()) : empty(); }
throw new IllegalArgumentException("shift = " + shift); if (source.isEmpty()) return StreamEx.empty(); return of(new RangeBasedSpliterator.OfSubLists<>(source, length, shift));
checkNonNegative("n", n); if (k > n) { return StreamEx.empty();