@Override public Iterator<T> iterator() { return Spliterators.iterator(spliterator()); }
@Override public void forEachOrdered(Consumer<? super T> action) { if (spliterator != null && !isParallel()) { spliterator().forEachRemaining(action); } else { if (context.fjp != null) context.terminate(() -> { stream().forEachOrdered(action); return null; }); else { stream().forEachOrdered(action); } } }
@Override public void forEach(Consumer<? super T> action) { if (spliterator != null && !isParallel()) { spliterator().forEachRemaining(action); } else { if (context.fjp != null) context.terminate(() -> { stream().forEach(action); return null; }); else { stream().forEach(action); } } }
<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); }
Spliterator<T> spltr = spliterator(); return supply(spltr.hasCharacteristics(Spliterator.ORDERED) ? new PrefixOps.OfRef<>(spltr, op) : new PrefixOps.OfUnordRef<T>(spltr, op));
/** * Returns an {@link StreamEx} object which wraps given {@link Stream}. * * <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 <T> the type of stream elements * @param stream original stream * @return the wrapped stream */ public static <T> StreamEx<T> of(Stream<T> stream) { if (stream instanceof AbstractStreamEx) { @SuppressWarnings("unchecked") AbstractStreamEx<T, ?> ase = (AbstractStreamEx<T, ?>) stream; if (ase.spliterator != null) return new StreamEx<>(ase.spliterator(), ase.context); return new StreamEx<>(ase.stream(), ase.context); } return new StreamEx<>(stream, StreamContext.of(stream)); }
/** * Returns an {@code EntryStream} object which wraps given {@link Stream} of * {@link Entry} elements * * @param <K> the type of original stream keys * @param <V> the type of original stream values * @param stream original stream * @return the wrapped stream */ public static <K, V> EntryStream<K, V> of(Stream<? extends Entry<K, V>> stream) { if (stream instanceof AbstractStreamEx) { @SuppressWarnings("unchecked") AbstractStreamEx<Entry<K, V>, ?> ase = (AbstractStreamEx<Entry<K, V>, ?>) stream; if (ase.spliterator != null) return new EntryStream<>(ase.spliterator(), ase.context); return new EntryStream<>(ase.stream(), ase.context); } return new EntryStream<>(stream, StreamContext.of(stream)); }
BiConsumer<A, ? super T> acc = collector.accumulator(); BinaryOperator<A> combiner = collector.combiner(); Spliterator<T> spliterator = spliterator(); if (!isParallel()) { A a = collector.supplier().get();
if (atLeast <= 1) return distinct(); Spliterator<T> spliterator = spliterator(); Spliterator<T> result; if (spliterator.hasCharacteristics(Spliterator.DISTINCT))