/** * Returns a new {@code EntryStream} which is a concatenation of the * supplied key-value pair and this stream. * * <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 key the key of the new {@code Entry} to prepend to this stream * @param value the value of the new {@code Entry} to prepend to this stream * @return the new stream */ public EntryStream<K, V> prepend(K key, V value) { return supply(new PrependSpliterator<>(spliterator(), new SimpleImmutableEntry<>(key, value))); }
}, spliterator()), context).mapToEntry(pb -> pb.a, pb -> pb.b);
/** * Merge series of adjacent stream entries with equal keys combining the * corresponding values using the provided function. * * <p> * This is a <a href="package-summary.html#StreamOps">quasi-intermediate</a> * partial reduction operation. * * <p> * The key of the resulting entry is the key of the first merged entry. * * @param merger a non-interfering, stateless, associative function to merge * values of two adjacent entries which keys are equal. Note that it * can be applied to the results if previous merges. * @return a new {@code EntryStream} which keys are the keys of the original * stream and the values are values of the adjacent entries with the * same keys, combined using the provided merger function. * @see StreamEx#collapse(BiPredicate, BinaryOperator) * @since 0.5.5 */ public EntryStream<K, V> collapseKeys(BinaryOperator<V> merger) { BinaryOperator<Entry<K, V>> entryMerger = (e1, e2) -> new SimpleImmutableEntry<>(e1.getKey(), merger.apply(e1 .getValue(), e2.getValue())); return new EntryStream<>(new CollapseSpliterator<>(equalKeys(), Function.identity(), entryMerger, entryMerger, spliterator()), context); }
/** * Drains the stream content into the supplied {@code Map}. * * <p> * This is a <a href="package-summary.html#StreamOps">terminal</a> * operation. * * @param <M> type of the resulting map * @param map a mutable map to put the stream elements into * @return the supplied map, updated from this stream * @throws IllegalStateException if this stream contains duplicate keys, or * the stream contains the key which was already present in the map * (according to {@link Object#equals(Object)}) * @since 0.6.3 */ public <M extends Map<K, V>> M into(M map) { Consumer<? super Entry<K, V>> cons = toMapConsumer(map); if (isParallel()) { if (map instanceof ConcurrentMap) forEach(cons); else toMap().entrySet().forEach(cons); } else { spliterator().forEachRemaining(cons); } return map; }
pb1.b = combiner.apply(pb1.b, pb2.b); return pb1; }, spliterator()), context).mapToEntry(pb -> pb.a, pb -> finisher.apply(pb.b));