/** * Returns a sequential unordered {@code LongStreamEx} of given length which * elements are equal to supplied value. * * @param value the constant value * @param length the length of the stream * @return a new {@code LongStreamEx} * @since 0.1.2 */ public static LongStreamEx constant(long value, long length) { return of(new ConstSpliterator.OfLong(value, length, false)); }
/** * Returns a sequential {@code LongStreamEx} containing a single element. * * @param element the single element * @return a singleton sequential stream */ public static LongStreamEx of(long element) { return of(new ConstSpliterator.OfLong(element, 1, true)); }
/** * Returns a sequential ordered {@code LongStreamEx} whose elements are the * specified values. * * @param elements the elements of the new stream * @return the new stream */ public static LongStreamEx of(long... elements) { return of(Arrays.spliterator(elements)); }
/** * Returns the stream which covers all the elements emitted by this * emitter. * * @return the new stream */ default LongStreamEx stream() { return of(spliterator()); } }
/** * Returns an empty sequential {@code LongStreamEx}. * * @return an empty sequential stream */ public static LongStreamEx empty() { return of(Spliterators.emptyLongSpliterator()); }
/** * Returns a sequential, ordered {@link LongStreamEx} created from given * {@link java.util.PrimitiveIterator.OfLong}. * * <p> * This method is roughly equivalent to * {@code LongStreamEx.of(Spliterators.spliteratorUnknownSize(iterator, ORDERED))} * , but may show better performance for parallel processing. * * <p> * Use this method only if you cannot provide better Stream source. * * @param iterator an iterator to create the stream from. * @return the new stream * @since 0.5.1 */ public static LongStreamEx of(PrimitiveIterator.OfLong iterator) { return of(new UnknownSizeSpliterator.USOfLong(iterator)); }
/** * Returns a sequential {@link LongStreamEx} with the specified range of the * specified array as its source. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code LongStreamEx} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 0.1.1 * @see Arrays#stream(long[], int, int) */ public static LongStreamEx of(long[] array, int startInclusive, int endExclusive) { return of(Arrays.spliterator(array, startInclusive, endExclusive)); }
return of(spliterator);
/** * Returns a sequential {@code LongStreamEx} containing an * {@link OptionalLong} value, if present, otherwise returns an empty * {@code LongStreamEx}. * * @param optional the optional to create a stream of * @return a stream with an {@code OptionalLong} value if present, otherwise * an empty stream * @since 0.1.1 */ public static LongStreamEx of(OptionalLong optional) { return optional.isPresent() ? of(optional.getAsLong()) : empty(); }
/** * Returns a sequential {@code LongStreamEx} containing the results of * applying the given function to the corresponding pairs of values in given * two arrays. * * @param first the first array * @param second the second array * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding array elements. * @return a new {@code LongStreamEx} * @throws IllegalArgumentException if length of the arrays differs. * @since 0.2.1 */ public static LongStreamEx zip(long[] first, long[] second, LongBinaryOperator mapper) { return of(new RangeBasedSpliterator.ZipLong(0, checkLength(first.length, second.length), mapper, first, second)); }
/** * Returns a new stream containing all the elements of the original stream interspersed with * given delimiter. * * <p> * For example, {@code LongStreamEx.of(1, 2, 3).intersperse(4)} will yield a stream containing * five elements: 1, 4, 2, 4, 3. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate operation</a>. * * @param delimiter a delimiter to be inserted between each pair of elements * @return the new stream * @since 0.6.6 */ public LongStreamEx intersperse(int delimiter) { return new LongStreamEx(stream().flatMap(s -> LongStreamEx.of(delimiter, s)).skip(1), context); }