@Override public S limit(long maxSize) { return supply(stream().limit(maxSize)); }
@Override public S sorted() { return supply(stream().sorted()); }
@Override public S peek(Consumer<? super T> action) { return supply(stream().peek(action)); }
@Override public S sorted(Comparator<? super T> comparator) { return supply(stream().sorted(comparator)); }
@Override public S filter(Predicate<? super T> predicate) { return supply(stream().filter(predicate)); }
@Override public S distinct() { return supply(stream().distinct()); }
@Override public S skip(long n) { return supply(stream().skip(n)); }
@Override @SuppressWarnings("unchecked") <T, S extends AbstractStreamEx<T, S>> S callWhile(AbstractStreamEx<T, S> stream, Predicate<? super T> predicate, boolean drop) { try { return stream.supply((Stream<T>) JDK9_METHODS[IDX_STREAM][drop ? IDX_DROP_WHILE : IDX_TAKE_WHILE] .invokeExact(stream.stream(), predicate)); } catch (Error | RuntimeException e) { throw e; } catch (Throwable e) { throw new InternalError(e); } }
/** * Returns a new stream containing all the elements of the original stream interspersed with * given delimiter. * * <p> * For example, {@code StreamEx.of("a", "b", "c").intersperse("x")} will yield a stream containing * five elements: a, x, b, x, c. * * <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 S intersperse(T delimiter) { return supply(stream().flatMap(s -> StreamEx.of(delimiter, s)).skip(1)); }
/** * Returns a stream consisting of the distinct elements of this stream * (according to object equality of the results of applying the given * function). * * <p> * For ordered streams, the selection of distinct elements is stable (for * duplicated elements, the element appearing first in the encounter order * is preserved.) For unordered streams, no stability guarantees are made. * * <p> * This is a <a href="package-summary.html#StreamOps">stateful intermediate * operation</a>. * * @param keyExtractor a non-interfering, stateless function which * classifies input elements. * @return the new stream * @since 0.3.8 */ public S distinct(Function<? super T, ?> keyExtractor) { return supply(stream().map(t -> new PairBox<>(t, keyExtractor.apply(t))).distinct().map(box -> box.a)); }
<T, S extends AbstractStreamEx<T, S>> S callWhile(AbstractStreamEx<T, S> stream, Predicate<? super T> predicate, boolean drop) { Spliterator<T> spltr = stream.spliterator(); return stream.supply( spltr.hasCharacteristics(Spliterator.ORDERED) ? new TakeDrop.TDOfRef<>(spltr, drop, false, predicate) : new TakeDrop.UnorderedTDOfRef<T>(spltr, drop, false, predicate)); }
return supply((isParallel() ? StreamSupport.stream(spliterator(), false) : stream()).skip(n).spliterator());
/** * Returns a stream consisting of all elements from this stream until the * first element which does not match the given predicate is found * (including the first mismatching element). * * <p> * This is a <a href="package-summary.html#StreamOps">quasi-intermediate * operation</a>. * * <p> * While this operation is quite cheap for sequential stream, it can be * quite expensive on parallel pipelines. Using unordered source or making it * explicitly unordered with {@link #unordered()} call may improve the parallel * processing performance if semantics permit. * * @param predicate a non-interfering, stateless predicate to apply to * elements. * @return the new stream. * @since 0.5.5 * @see #takeWhile(Predicate) */ public S takeWhileInclusive(Predicate<? super T> predicate) { Objects.requireNonNull(predicate); Spliterator<T> spltr = spliterator(); return supply( spltr.hasCharacteristics(Spliterator.ORDERED) ? new TakeDrop.TDOfRef<>(spltr, false, true, predicate) : new TakeDrop.UnorderedTDOfRef<T>(spltr, false, true, predicate)); }
@SuppressWarnings("unchecked") S prependSpliterator(Stream<? extends T> other, Spliterator<? extends T> left) { if (left.getExactSizeIfKnown() == 0) return (S) this; Spliterator<T> right = spliterator(); Spliterator<T> result; if (right.getExactSizeIfKnown() == 0) result = (Spliterator<T>) left; else result = new TailConcatSpliterator<>(left, right); context = context.combine(other); return supply(result); }
@SuppressWarnings("unchecked") S appendSpliterator(Stream<? extends T> other, Spliterator<? extends T> right) { if (right.getExactSizeIfKnown() == 0) return (S) this; Spliterator<T> left = spliterator(); Spliterator<T> result; if (left.getExactSizeIfKnown() == 0) result = (Spliterator<T>) right; else result = new TailConcatSpliterator<>(left, right); context = context.combine(other); return supply(result); }
@SuppressWarnings("unchecked") S ifEmpty(Stream<? extends T> other, Spliterator<? extends T> right) { if (right.getExactSizeIfKnown() == 0) return (S) this; Spliterator<T> left = spliterator(); Spliterator<T> result; if (left.getExactSizeIfKnown() == 0) result = (Spliterator<T>) right; else result = new IfEmptySpliterator<>(left, right); context = context.combine(other); return supply(result); }
return supply(spltr.hasCharacteristics(Spliterator.ORDERED) ? new PrefixOps.OfRef<>(spltr, op) : new PrefixOps.OfUnordRef<T>(spltr, op));
else result = new DistinctSpliterator<>(spliterator, atLeast); return supply(result);