/** * Returns a sequential {@code EntryStream} containing {@code Entry} objects * composed from corresponding key and value in given two lists. * * <p> * The keys and values are accessed using {@link List#get(int)}, so the * lists should provide fast random access. The lists are assumed to be * unmodifiable during the stream operations. * * @param <K> the type of stream element keys * @param <V> the type of stream element values * @param keys the list of keys, assumed to be unmodified during use * @param values the list of values, assumed to be unmodified during use * @return a new {@code EntryStream} * @throws IllegalArgumentException if length of the lists differs. * @see StreamEx#zip(List, List, BiFunction) * @since 0.2.1 */ public static <K, V> EntryStream<K, V> zip(List<K> keys, List<V> values) { return of(new RangeBasedSpliterator.ZipRef<>(0, checkLength(keys.size(), values.size()), SimpleImmutableEntry::new, keys, values)); }
public PermutationSpliterator(int length) { StreamExInternals.checkNonNegative("Length", length); if (length >= factorials.length) throw new IllegalArgumentException("Length " + length + " is bigger than " + factorials.length + ": not supported"); this.value = new int[length]; for (int i = 0; i < length; i++) this.value[i] = i; this.fence = this.remainingSize = factorials[length]; }
/** * Returns a {@code DoubleCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, in * encounter order. * * @param delimiter the delimiter to be used between each element * @return A {@code DoubleCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static DoubleCollector<?, String> joining(CharSequence delimiter) { return PartialCollector.joining(delimiter, null, null, false).asDouble( StreamExInternals.joinAccumulatorDouble(delimiter)); }
void clear() { other = null; payload = none(); } }
Predicate<A> finished = finished(downstream); if (finished != null) { BiConsumer<A, ? super T> accumulator = downstream.accumulator();
/** * Returns a sequential {@link DoubleStreamEx} with the specified range of * the specified array as its source. Array values will be casted to double. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code IntStreamEx} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 0.2.0 */ public static DoubleStreamEx of(float[] array, int startInclusive, int endExclusive) { rangeCheck(array.length, startInclusive, endExclusive); return of(new RangeBasedSpliterator.OfFloat(startInclusive, endExclusive, array)); }
/** * Returns a {@code LongCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, in * encounter order. * * @param delimiter the delimiter to be used between each element * @return A {@code LongCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static LongCollector<?, String> joining(CharSequence delimiter) { return PartialCollector.joining(delimiter, null, null, false).asLong( StreamExInternals.joinAccumulatorLong(delimiter)); }
/** * Returns an {@code IntCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, in * encounter order. * * @param delimiter the delimiter to be used between each element * @return An {@code IntCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static IntCollector<?, String> joining(CharSequence delimiter) { return PartialCollector.joining(delimiter, null, null, false).asInt( StreamExInternals.joinAccumulatorInt(delimiter)); }
private Spliterator<R> arraySplit() { long s = estimateSize(); if (s <= 1) return null; int n = batch + BATCH_UNIT; if (n > s) n = (int) s; if (n > MAX_BATCH) n = MAX_BATCH; @SuppressWarnings("unchecked") R[] array = (R[]) new Object[n]; int index = drainTo(array, this); if((batch = index) == 0) return null; long s2 = estimateSize(); USOfRef<R> prefix = new UnknownSizeSpliterator.USOfRef<>(array, 0, index); if(hasCharacteristics(SUBSIZED)) prefix.est = index; else if(s == s2) prefix.est = Math.max(index, s/2); else prefix.est = Math.max(index, s2 - s); return prefix; }
static StreamContext of(BaseStream<?, ?> stream) { if (stream instanceof BaseStreamEx) return ((BaseStreamEx<?, ?, ?, ?>) stream).context; if (mustCloseStream(stream)) return new StreamContext(stream.isParallel()).onClose(stream::close); return stream.isParallel() ? PARALLEL : SEQUENTIAL; } }
CollapseSpliterator(BiPredicate<? super T, ? super T> mergeable, Function<T, R> mapper, BiFunction<R, T, R> accumulator, BinaryOperator<R> combiner, Spliterator<T> source) { super(none()); this.source = source; this.mergeable = mergeable; this.mapper = mapper; this.accumulator = accumulator; this.combiner = combiner; this.root = this; }
}; PartialCollector<Map<K, A>, M> partial = PartialCollector.grouping(mapFactory, downstream); Predicate<A> downstreamFinished = finished(downstream); if (downstreamFinished != null) { int size = domain.size();
/** * Returns a sequential {@link IntStreamEx} with the specified range of the * specified array as its source. Array values will be casted to int. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code IntStreamEx} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 0.2.0 */ public static IntStreamEx of(char[] array, int startInclusive, int endExclusive) { rangeCheck(array.length, startInclusive, endExclusive); return of(new RangeBasedSpliterator.OfChar(startInclusive, endExclusive, array)); }
/** * Returns a {@code LongCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, with * the specified prefix and suffix, in encounter order. * * @param delimiter the delimiter to be used between each element * @param prefix the sequence of characters to be used at the beginning of * the joined result * @param suffix the sequence of characters to be used at the end of the * joined result * @return A {@code LongCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static LongCollector<?, String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix) { return PartialCollector.joining(delimiter, prefix, suffix, true).asLong( StreamExInternals.joinAccumulatorLong(delimiter)); }
/** * Returns an {@code IntCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, with * the specified prefix and suffix, in encounter order. * * @param delimiter the delimiter to be used between each element * @param prefix the sequence of characters to be used at the beginning of * the joined result * @param suffix the sequence of characters to be used at the end of the * joined result * @return An {@code IntCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static IntCollector<?, String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix) { return PartialCollector.joining(delimiter, prefix, suffix, true).asInt( StreamExInternals.joinAccumulatorInt(delimiter)); }
private CollapseSpliterator(CollapseSpliterator<T, R> root, Spliterator<T> source, Connector<T, R> left, Connector<T, R> right) { super(none()); this.source = source; this.root = root; this.mergeable = root.mergeable; this.mapper = root.mapper; this.accumulator = root.accumulator; this.combiner = root.combiner; this.left = left; this.right = right; if (left != null) left.rhs = this; right.lhs = this; }
Predicate<A> finished = finished(downstream); if (finished != null) { return new CancellableCollectorImpl<>(downstream.supplier(), downstream.accumulator(), downstream
/** * Returns a sequential {@code DoubleStreamEx} containing the results of * applying the given function to the corresponding pairs of values in given * two arrays. * * @param first the first array * @param second the second array * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding array elements. * @return a new {@code DoubleStreamEx} * @throws IllegalArgumentException if length of the arrays differs. * @since 0.2.1 */ public static DoubleStreamEx zip(double[] first, double[] second, DoubleBinaryOperator mapper) { return of(new RangeBasedSpliterator.ZipDouble(0, checkLength(first.length, second.length), mapper, first, second)); }
/** * Returns a sequential {@link IntStreamEx} with the specified range of the * specified array as its source. Array values will be casted to int. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code IntStreamEx} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 0.2.0 */ public static IntStreamEx of(short[] array, int startInclusive, int endExclusive) { rangeCheck(array.length, startInclusive, endExclusive); return of(new RangeBasedSpliterator.OfShort(startInclusive, endExclusive, array)); }