return StreamEx.of(new ConstSpliterator.OfRef<>(Collections.emptyList(), 1, true)); return of(new CrossSpliterator.ToList<>(source));
return StreamEx.of(new ConstSpliterator.OfRef<>(Collections.emptyList(), 1, true)); return of(new CrossSpliterator.ToList<>(Collections.nCopies(n, source)));
@Override public Spliterator<U> trySplit() { if(spliterators == null) { spliterators = new ArrayList<>(); Stream<T> stream = getStart(); if(stream != null) { spliterators.add(new PairBox<>(stream.parallel().spliterator(), null)); closeHandler = stream::close; } return new ConstSpliterator.OfRef<>(getStartElement(), 1, true); } int size = spliterators.size(); if(size != 1) { return null; } Spliterator<T> prefix = spliterators.get(0).a.trySplit(); if(prefix == null) return null; TreeSpliterator<T, U> clone = doClone(); clone.size /= 2; this.size -= clone.size; clone.spliterators = new ArrayList<>(); clone.spliterators.add(new PairBox<>(prefix, null)); closeHandler = StreamContext.compose(closeHandler, clone::close); return clone; }
/** * Returns a new {@code StreamEx} which is a concatenation of this stream * and the supplied value. * * <p> * This is a <a href="package-summary.html#StreamOps">quasi-intermediate * operation</a> with <a href="package-summary.html#TSO">tail-stream * optimization</a>. * * @param value the value to append to the stream * @return the new stream * @since 0.5.4 */ public StreamEx<T> append(T value) { return appendSpliterator(null, new ConstSpliterator.OfRef<>(value, 1, true)); }
/** * Returns a new {@code EntryStream} which is a concatenation of this stream * and the supplied key-value pair. * * <p> * This is a <a href="package-summary.html#StreamOps">quasi-intermediate * operation</a>. * * @param key the key of the new {@code Entry} to append to this stream * @param value the value of the new {@code Entry} to append to this stream * @return the new stream */ public EntryStream<K, V> append(K key, V value) { return appendSpliterator(null, new ConstSpliterator.OfRef<>(new SimpleImmutableEntry<>(key, value), 1, true)); }
/** * Returns a sequential unordered {@code StreamEx} of given length which * elements are equal to supplied value. * * @param <T> the type of stream elements * @param value the constant value * @param length the length of the stream * @return a new {@code StreamEx} * @since 0.1.2 */ public static <T> StreamEx<T> constant(T value, long length) { return of(new ConstSpliterator.OfRef<>(value, length, false)); }
@Override public Spliterator<T> trySplit() { if (mode == 0) return source.trySplit(); mode = 0; return new ConstSpliterator.OfRef<>(element, 1, true); }
/** * Returns a sequential {@code StreamEx} containing a single element. * * @param <T> the type of stream element * @param element the single element * @return a singleton sequential stream * @see Stream#of(Object) */ public static <T> StreamEx<T> of(T element) { return of(new ConstSpliterator.OfRef<>(element, 1, true)); }