/** * Returns a sequential {@link LongStreamEx} created from given * {@link java.util.Spliterator.OfLong}. * * @param spliterator a spliterator to create the stream from. * @return the new stream * @since 0.3.4 */ public static LongStreamEx of(Spliterator.OfLong spliterator) { return new LongStreamEx(spliterator, StreamContext.SEQUENTIAL); }
private static LongStreamEx seq(LongStream stream) { return new LongStreamEx(stream, StreamContext.SEQUENTIAL); }
final LongStreamEx delegate(Spliterator.OfLong spliterator) { return new LongStreamEx(spliterator, context); }
@Override public LongStreamEx mapToLong(ToLongFunction<? super T> mapper) { return new LongStreamEx(stream().mapToLong(mapper), context); }
@Override final LongStreamEx callWhile(LongStreamEx stream, LongPredicate predicate, boolean drop) { try { return new LongStreamEx((LongStream) JDK9_METHODS[IDX_LONG_STREAM][drop ? IDX_DROP_WHILE : IDX_TAKE_WHILE] .invokeExact(stream.stream(), predicate), stream.context); } catch (Error | RuntimeException e) { throw e; } catch (Throwable e) { throw new InternalError(e); } }
@Override public LongStreamEx filter(LongPredicate predicate) { return new LongStreamEx(stream().filter(predicate), context); }
@Override public LongStreamEx sorted() { return new LongStreamEx(stream().sorted(), context); }
@Override public LongStreamEx mapToLong(IntToLongFunction mapper) { return new LongStreamEx(stream().mapToLong(mapper), context); }
@Override public LongStreamEx skip(long n) { return new LongStreamEx(stream().skip(n), context); }
@Override public LongStreamEx asLongStream() { return new LongStreamEx(stream().asLongStream(), context); }
@Override public LongStreamEx peek(LongConsumer action) { return new LongStreamEx(stream().peek(action), context); }
@Override public LongStreamEx mapToLong(DoubleToLongFunction mapper) { return new LongStreamEx(stream().mapToLong(mapper), context); }
@Override public LongStreamEx map(LongUnaryOperator mapper) { return new LongStreamEx(stream().map(mapper), context); }
@Override public LongStreamEx distinct() { return new LongStreamEx(stream().distinct(), context); }
@Override public LongStreamEx flatMapToLong(Function<? super T, ? extends LongStream> mapper) { return new LongStreamEx(stream().flatMapToLong(mapper), context); }
@Override public LongStreamEx flatMap(LongFunction<? extends LongStream> mapper) { return new LongStreamEx(stream().flatMap(mapper), context); }
@Override public LongStreamEx limit(long maxSize) { return new LongStreamEx(stream().limit(maxSize), context); }
/** * Creates a lazily concatenated stream whose elements are all the elements * of this stream followed by all the elements of the other stream. The * resulting stream is ordered if both of the input streams are ordered, and * parallel if either of the input streams is parallel. When the resulting * stream is closed, the close handlers for both input streams are invoked. * * @param other the other stream * @return this stream appended by the other stream * @see LongStream#concat(LongStream, LongStream) */ public LongStreamEx append(LongStream other) { return new LongStreamEx(LongStream.concat(stream(), other), context.combine(other)); }
/** * Creates a lazily concatenated stream whose elements are all the elements * of the other stream followed by all the elements of this stream. The * resulting stream is ordered if both of the input streams are ordered, and * parallel if either of the input streams is parallel. When the resulting * stream is closed, the close handlers for both input streams are invoked. * * @param other the other stream * @return this stream prepended by the other stream * @see LongStream#concat(LongStream, LongStream) */ public LongStreamEx prepend(LongStream other) { return new LongStreamEx(LongStream.concat(other, stream()), context.combine(other)); }
/** * Returns a stream consisting of the elements of this stream in reverse * sorted order. * * <p> * This is a stateful intermediate operation. * * @return the new stream * @since 0.0.8 */ public LongStreamEx reverseSorted() { LongUnaryOperator inv = x -> ~x; return new LongStreamEx(stream().map(inv).sorted().map(inv), context); }