/** * Returns a sequential {@link IntStreamEx} created from given * {@link java.util.Spliterator.OfInt}. * * @param spliterator a spliterator to create the stream from. * @return the new stream * @since 0.3.4 */ public static IntStreamEx of(Spliterator.OfInt spliterator) { return new IntStreamEx(spliterator, StreamContext.SEQUENTIAL); }
private static IntStreamEx seq(IntStream stream) { return new IntStreamEx(stream, StreamContext.SEQUENTIAL); }
final IntStreamEx delegate(Spliterator.OfInt spliterator) { return new IntStreamEx(spliterator, context); }
@Override public IntStreamEx filter(IntPredicate predicate) { return new IntStreamEx(stream().filter(predicate), context); }
@Override public IntStreamEx mapToInt(ToIntFunction<? super T> mapper) { return new IntStreamEx(stream().mapToInt(mapper), context); }
/** * Returns an {@code IntStreamEx} object which wraps given {@link IntStream} * . * * <p> * The supplied stream must not be consumed or closed when this method is * called. No operation must be performed on the supplied stream after it's * wrapped. * * @param stream original stream * @return the wrapped stream * @since 0.0.8 */ public static IntStreamEx of(IntStream stream) { return stream instanceof IntStreamEx ? (IntStreamEx) stream : new IntStreamEx(stream, StreamContext.of(stream)); }
@Override final IntStreamEx callWhile(IntStreamEx stream, IntPredicate predicate, boolean drop) { try { return new IntStreamEx((IntStream) JDK9_METHODS[IDX_INT_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 IntStreamEx skip(long n) { return new IntStreamEx(stream().skip(n), context); }
@Override public IntStreamEx flatMapToInt(Function<? super T, ? extends IntStream> mapper) { return new IntStreamEx(stream().flatMapToInt(mapper), context); }
@Override public IntStreamEx map(IntUnaryOperator mapper) { return new IntStreamEx(stream().map(mapper), context); }
@Override public IntStreamEx distinct() { return new IntStreamEx(stream().distinct(), context); }
@Override public IntStreamEx limit(long maxSize) { return new IntStreamEx(stream().limit(maxSize), context); }
@Override public IntStreamEx sorted() { return new IntStreamEx(stream().sorted(), context); }
@Override public IntStreamEx mapToInt(LongToIntFunction mapper) { return new IntStreamEx(stream().mapToInt(mapper), context); }
@Override public IntStreamEx mapToInt(DoubleToIntFunction mapper) { return new IntStreamEx(stream().mapToInt(mapper), context); }
@Override public IntStreamEx flatMap(IntFunction<? extends IntStream> mapper) { return new IntStreamEx(stream().flatMap(mapper), context); }
@Override public IntStreamEx peek(IntConsumer action) { return new IntStreamEx(stream().peek(action), context); }
/** * 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 IntStream#concat(IntStream, IntStream) */ public IntStreamEx prepend(IntStream other) { return new IntStreamEx(IntStream.concat(other, stream()), context.combine(other)); }
/** * 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 IntStream#concat(IntStream, IntStream) */ public IntStreamEx append(IntStream other) { return new IntStreamEx(IntStream.concat(stream(), other), 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 IntStreamEx reverseSorted() { IntUnaryOperator inv = x -> ~x; return new IntStreamEx(stream().map(inv).sorted().map(inv), context); }