Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.landawn.abacus.util.stream.EntryStream Maven / Gradle / Ivy
Go to download
A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.
/*
* Copyright (C) 2016, 2017, 2018, 2019 HaiYang Li
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.landawn.abacus.util.stream;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Executor;
import com.landawn.abacus.annotation.Beta;
import com.landawn.abacus.annotation.IntermediateOp;
import com.landawn.abacus.annotation.LazyEvaluation;
import com.landawn.abacus.annotation.ParallelSupported;
import com.landawn.abacus.annotation.SequentialOnly;
import com.landawn.abacus.annotation.TerminalOp;
import com.landawn.abacus.annotation.TerminalOpTriggered;
import com.landawn.abacus.exception.DuplicatedResultException;
import com.landawn.abacus.util.AsyncExecutor;
import com.landawn.abacus.util.BiIterator;
import com.landawn.abacus.util.Comparators;
import com.landawn.abacus.util.Fn;
import com.landawn.abacus.util.If.OrElse;
import com.landawn.abacus.util.ImmutableMap;
import com.landawn.abacus.util.Indexed;
import com.landawn.abacus.util.Joiner;
import com.landawn.abacus.util.ListMultimap;
import com.landawn.abacus.util.LongMultiset;
import com.landawn.abacus.util.MergeResult;
import com.landawn.abacus.util.Multimap;
import com.landawn.abacus.util.Multiset;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.NoCachingNoUpdating;
import com.landawn.abacus.util.NoCachingNoUpdating.DisposableEntry;
import com.landawn.abacus.util.ObjIterator;
import com.landawn.abacus.util.Pair;
import com.landawn.abacus.util.Percentage;
import com.landawn.abacus.util.Throwables;
import com.landawn.abacus.util.u.Optional;
import com.landawn.abacus.util.function.BiConsumer;
import com.landawn.abacus.util.function.BiFunction;
import com.landawn.abacus.util.function.BiPredicate;
import com.landawn.abacus.util.function.BinaryOperator;
import com.landawn.abacus.util.function.BooleanSupplier;
import com.landawn.abacus.util.function.Consumer;
import com.landawn.abacus.util.function.Function;
import com.landawn.abacus.util.function.Predicate;
import com.landawn.abacus.util.function.Supplier;
import com.landawn.abacus.util.function.ToDoubleFunction;
import com.landawn.abacus.util.function.ToIntFunction;
import com.landawn.abacus.util.function.ToLongFunction;
/**
* The Stream will be automatically closed after execution(A terminal method is executed/triggered).
*
* @see BaseStream
* @see Stream
* @see IntStream
* @see LongStream
* @see DoubleStream
* @see EntryStream
* @see com.landawn.abacus.util.ExceptionalStream
* @see Collectors
* @see com.landawn.abacus.util.Fn
* @see com.landawn.abacus.util.Comparators
*/
@com.landawn.abacus.annotation.Immutable
@LazyEvaluation
public final class EntryStream extends
StreamBase, Object[], Predicate super Map.Entry>, Consumer super Map.Entry>, List>, Optional>, Indexed>, ObjIterator>, EntryStream> {
private static final Function, Stream>> mapper_func = t -> Stream.of(t);
final Map m;
final Stream> s;
EntryStream(final Stream extends Map.Entry extends K, ? extends V>> s) {
this(null, s);
}
@SuppressWarnings("rawtypes")
EntryStream(final Map extends K, ? extends V> m, final Stream extends Map.Entry extends K, ? extends V>> s) {
super(s.sorted, (Comparator>) s.cmp, s.closeHandlers);
this.m = (Map) m;
this.s = (Stream>) s;
}
@SequentialOnly
@IntermediateOp
public Stream keys() {
// It won't be parallel stream if m != null.
if (m != null) {
return Stream.of(m.keySet());
}
final Function, K> func = Fn.key();
if (isParallel()) {
return s.psp(ss -> ss.map(func));
} else {
return s.map(func);
}
}
@SequentialOnly
@IntermediateOp
public Stream values() {
// It won't be parallel stream if m != null.
if (m != null) {
return Stream.of(m.values());
}
final Function, V> func = Fn.value();
if (isParallel()) {
return s.psp(ss -> ss.map(func));
} else {
return s.map(func);
}
}
@SequentialOnly
@IntermediateOp
public Stream> entries() {
return s;
}
@SequentialOnly
@IntermediateOp
public EntryStream inversed() {
final Function, Map.Entry> mapper = Fn.inverse();
if (isParallel()) {
return of(s.>> psp(ss -> ss.map(mapper)));
} else {
return map(mapper);
}
}
/**
* Returns a stream consisting of the elements of this stream which keys are
* instances of given class.
*
*
* This is an intermediate
* operation.
*
* @param a type of keys to select.
* @param clazz a class to filter the keys.
* @return
*/
@SuppressWarnings({ "unchecked" })
@SequentialOnly
@IntermediateOp
public EntryStream selectByKey(Class clazz) {
if (isParallel()) {
return (EntryStream) sequential().filterByKey(Fn.instanceOf(clazz))
.parallel(maxThreadNum(), splitor(), asyncExecutor(), cancelUncompletedThreads());
} else {
return (EntryStream) filterByKey(Fn.instanceOf(clazz));
}
}
/**
* Returns a stream consisting of the elements of this stream which values
* are instances of given class.
*
*
* This is an intermediate
* operation.
*
* @param a type of values to select.
* @param clazz a class to filter the values.
* @return
*/
@SuppressWarnings({ "unchecked" })
@SequentialOnly
@IntermediateOp
public EntryStream selectByValue(Class clazz) {
if (isParallel()) {
return (EntryStream) sequential().filterByValue(Fn.instanceOf(clazz))
.parallel(maxThreadNum(), splitor(), asyncExecutor(), cancelUncompletedThreads());
} else {
return (EntryStream) filterByValue(Fn.instanceOf(clazz));
}
}
@Override
public EntryStream filter(final Predicate super Map.Entry> predicate) {
return of(s.filter(predicate));
}
@ParallelSupported
@IntermediateOp
public EntryStream filter(final BiPredicate super K, ? super V> predicate) {
return of(s.filter(Fn.Entries.p(predicate)));
}
@Override
public EntryStream filter(Predicate super Map.Entry> predicate, Consumer super Map.Entry> actionOnDroppedItem) {
return of(s.filter(predicate, actionOnDroppedItem));
}
@ParallelSupported
@IntermediateOp
public EntryStream filterByKey(final Predicate super K> keyPredicate) {
final Predicate> predicate = Fn.testByKey(keyPredicate);
return of(s.filter(predicate));
}
@ParallelSupported
@IntermediateOp
public EntryStream filterByValue(final Predicate super V> valuePredicate) {
final Predicate> predicate = Fn.testByValue(valuePredicate);
return of(s.filter(predicate));
}
/**
*
* @param
* @param predicate
* @return
* @deprecated
*/
@Deprecated
@Override
public EntryStream removeIf(final Predicate super Map.Entry> predicate) {
return of(s.removeIf(predicate));
}
/**
*
* @param
* @param predicate
* @return
* @deprecated
*/
@ParallelSupported
@Deprecated
public EntryStream removeIf(final BiPredicate super K, ? super V> predicate) {
return of(s.removeIf(Fn.Entries.p(predicate)));
}
@Deprecated
@Override
public EntryStream removeIf(Predicate super Map.Entry> predicate, Consumer super Map.Entry> actionOnDroppedItem) {
return of(s.removeIf(predicate, actionOnDroppedItem));
}
@Override
public EntryStream takeWhile(final Predicate super Map.Entry> predicate) {
return of(s.takeWhile(predicate));
}
@ParallelSupported
@IntermediateOp
public EntryStream takeWhile(final BiPredicate super K, ? super V> predicate) {
return of(s.takeWhile(Fn.Entries.p(predicate)));
}
@Override
public EntryStream dropWhile(final Predicate super Map.Entry> predicate) {
return of(s.dropWhile(predicate));
}
@ParallelSupported
@IntermediateOp
public EntryStream dropWhile(final BiPredicate super K, ? super V> predicate) {
return of(s.dropWhile(Fn.Entries.p(predicate)));
}
@Override
public EntryStream dropWhile(Predicate super Map.Entry> predicate, Consumer super Map.Entry> actionOnDroppedItem) {
return of(s.dropWhile(predicate, actionOnDroppedItem));
}
@Override
public EntryStream skipUntil(final Predicate super Map.Entry> predicate) {
return of(s.skipUntil(predicate));
}
@ParallelSupported
@IntermediateOp
public EntryStream skipUntil(final BiPredicate super K, ? super V> predicate) {
return of(s.skipUntil(Fn.Entries.p(predicate)));
}
@ParallelSupported
@IntermediateOp
public EntryStream map(final Function super Map.Entry, ? extends Map.Entry extends KK, ? extends VV>> mapper) {
return s.mapToEntry(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream map(final Function super Map.Entry, ? extends KK> keyMapper,
final Function super Map.Entry, ? extends VV> valueMapper) {
return s.mapToEntry(keyMapper, valueMapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream map(final BiFunction super K, ? super V, ? extends Map.Entry extends KK, ? extends VV>> mapper) {
return map(Fn.Entries.f(mapper));
}
@ParallelSupported
@IntermediateOp
public EntryStream map(final BiFunction super K, ? super V, ? extends KK> keyMapper,
final BiFunction super K, ? super V, ? extends VV> valueMapper) {
final Function, Map.Entry> mapper = t -> new SimpleImmutableEntry<>(keyMapper.apply(t.getKey(), t.getValue()),
valueMapper.apply(t.getKey(), t.getValue()));
return map(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream mapKey(final Function super K, ? extends KK> keyMapper) {
final Function, Map.Entry> mapper = Fn.mapKey(keyMapper);
return map(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream mapKey(final BiFunction super K, ? super V, ? extends KK> keyMapper) {
final Function, Map.Entry> mapper = entry -> new SimpleImmutableEntry<>(keyMapper.apply(entry.getKey(), entry.getValue()),
entry.getValue());
return map(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream mapValue(final Function super V, ? extends VV> valueMapper) {
final Function, Map.Entry> mapper = Fn.mapValue(valueMapper);
return map(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream mapValue(final BiFunction super K, ? super V, ? extends VV> valueMapper) {
final Function, Map.Entry> mapper = entry -> new SimpleImmutableEntry<>(entry.getKey(),
valueMapper.apply(entry.getKey(), entry.getValue()));
return map(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream mapKeyPartial(final Function super K, ? extends Optional extends KK>> keyMapper) {
final Map.Entry emptyEntry = new SimpleImmutableEntry<>(null, null);
final Function, Map.Entry> mapper = entry -> {
final Optional extends KK> op = keyMapper.apply(entry.getKey());
return op.isPresent() ? new SimpleImmutableEntry<>(op.get(), entry.getValue()) : emptyEntry;
};
if (this.isParallel()) {
return map(mapper).psp(s -> s.filter(it -> it != emptyEntry));
} else {
return map(mapper).filter(it -> it != emptyEntry);
}
}
@ParallelSupported
@IntermediateOp
public EntryStream mapKeyPartial(final BiFunction super K, ? super V, ? extends Optional extends KK>> keyMapper) {
final Map.Entry emptyEntry = new SimpleImmutableEntry<>(null, null);
final Function, Map.Entry> mapper = entry -> {
final Optional extends KK> op = keyMapper.apply(entry.getKey(), entry.getValue());
return op.isPresent() ? new SimpleImmutableEntry<>(op.get(), entry.getValue()) : emptyEntry;
};
if (this.isParallel()) {
return map(mapper).psp(s -> s.filter(it -> it != emptyEntry));
} else {
return map(mapper).filter(it -> it != emptyEntry);
}
}
@ParallelSupported
@IntermediateOp
public EntryStream mapValuePartial(final Function super V, ? extends Optional extends VV>> valueMapper) {
final Map.Entry emptyEntry = new SimpleImmutableEntry<>(null, null);
final Function, Map.Entry> mapper = entry -> {
final Optional extends VV> op = valueMapper.apply(entry.getValue());
return op.isPresent() ? new SimpleImmutableEntry<>(entry.getKey(), op.get()) : emptyEntry;
};
if (this.isParallel()) {
return map(mapper).psp(s -> s.filter(it -> it != emptyEntry));
} else {
return map(mapper).filter(it -> it != emptyEntry);
}
}
@ParallelSupported
@IntermediateOp
public EntryStream mapValuePartial(final BiFunction super K, ? super V, ? extends Optional extends VV>> valueMapper) {
final Map.Entry emptyEntry = new SimpleImmutableEntry<>(null, null);
final Function, Map.Entry> mapper = entry -> {
final Optional extends VV> op = valueMapper.apply(entry.getKey(), entry.getValue());
return op.isPresent() ? new SimpleImmutableEntry<>(entry.getKey(), op.get()) : emptyEntry;
};
if (this.isParallel()) {
return map(mapper).psp(s -> s.filter(it -> it != emptyEntry));
} else {
return map(mapper).filter(it -> it != emptyEntry);
}
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMap(final Function super Map.Entry, ? extends EntryStream extends KK, ? extends VV>> mapper) {
return s.flatMappToEntry(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMap(final BiFunction super K, ? super V, ? extends EntryStream extends KK, ? extends VV>> mapper) {
return flatMap(Fn.Entries.f(mapper));
}
@ParallelSupported
@IntermediateOp
public EntryStream flattMap(final Function super Map.Entry, ? extends Map extends KK, ? extends VV>> mapper) {
return s.flattMapToEntry(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream flattMap(final BiFunction super K, ? super V, ? extends Map extends KK, ? extends VV>> mapper) {
return flattMap(Fn.Entries.f(mapper));
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMapp(
final Function super Map.Entry, ? extends Stream extends Map.Entry extends KK, ? extends VV>>> mapper) {
return s.flatMapToEntry(mapper);
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMapp(
final BiFunction super K, ? super V, ? extends Stream extends Map.Entry extends KK, ? extends VV>>> mapper) {
return flatMapp(Fn.Entries.f(mapper));
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMapKey(final Function super K, ? extends Stream extends KK>> keyMapper) {
final Function, Stream>> mapper2 = e -> keyMapper.apply(e.getKey())
.map(kk -> new SimpleImmutableEntry<>(kk, e.getValue()));
return flatMapp(mapper2);
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMapKey(final BiFunction super K, ? super V, ? extends Stream extends KK>> keyMapper) {
final Function, Stream>> mapper2 = e -> keyMapper.apply(e.getKey(), e.getValue())
.map(kk -> new SimpleImmutableEntry<>(kk, e.getValue()));
return flatMapp(mapper2);
}
@ParallelSupported
@IntermediateOp
public EntryStream flattMapKey(final Function super K, ? extends Collection extends KK>> keyMapper) {
final Function, Stream>> mapper2 = e -> Stream.of(keyMapper.apply(e.getKey()))
.map(kk -> new SimpleImmutableEntry<>(kk, e.getValue()));
return flatMapp(mapper2);
}
@ParallelSupported
@IntermediateOp
public EntryStream flattMapKey(final BiFunction super K, ? super V, ? extends Collection extends KK>> keyMapper) {
final Function, Stream>> mapper2 = e -> Stream.of(keyMapper.apply(e.getKey(), e.getValue()))
.map(kk -> new SimpleImmutableEntry<>(kk, e.getValue()));
return flatMapp(mapper2);
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMapValue(final Function super V, ? extends Stream extends VV>> valueMapper) {
final Function, Stream>> mapper2 = e -> valueMapper.apply(e.getValue())
.map(vv -> new SimpleImmutableEntry<>(e.getKey(), vv));
return flatMapp(mapper2);
}
@ParallelSupported
@IntermediateOp
public EntryStream flatMapValue(final BiFunction super K, ? super V, ? extends Stream extends VV>> valueMapper) {
final Function, Stream>> mapper2 = e -> valueMapper.apply(e.getKey(), e.getValue())
.map(vv -> new SimpleImmutableEntry<>(e.getKey(), vv));
return flatMapp(mapper2);
}
@ParallelSupported
@IntermediateOp
public EntryStream flattMapValue(final Function super V, ? extends Collection extends VV>> valueMapper) {
final Function, Stream>> mapper2 = e -> Stream.of(valueMapper.apply(e.getValue()))
.map(vv -> new SimpleImmutableEntry<>(e.getKey(), vv));
return flatMapp(mapper2);
}
@ParallelSupported
@IntermediateOp
public EntryStream flattMapValue(final BiFunction super K, ? super V, ? extends Collection extends VV>> valueMapper) {
final Function, Stream>> mapper2 = e -> Stream.of(valueMapper.apply(e.getKey(), e.getValue()))
.map(vv -> new SimpleImmutableEntry<>(e.getKey(), vv));
return flatMapp(mapper2);
}
/**
*
* @param keyMapper
* @return
* @see Collectors#groupingBy(Function)
*/
@SequentialOnly
@IntermediateOp
@TerminalOpTriggered
public EntryStream> groupBy() {
final Function super Map.Entry, K> keyMapper = Fn.key();
final Function super Map.Entry, V> valueMapper = Fn.value();
if (isParallel()) {
return of(s.sequential().groupBy(keyMapper, valueMapper).parallel(s.maxThreadNum(), s.splitor(), s.asyncExecutor(), s.cancelUncompletedThreads()));
} else {
return of(s.groupBy(keyMapper, valueMapper));
}
}
/**
*
* @param keyMapper
* @param mapFactory
* @return
* @see Collectors#groupingBy(Function, Supplier)
*/
@SequentialOnly
@IntermediateOp
@TerminalOpTriggered
public EntryStream> groupBy(final Supplier extends Map>> mapFactory) {
final Function super Map.Entry, K> keyMapper = Fn.key();
final Function super Map.Entry, V> valueMapper = Fn.value();
if (isParallel()) {
return of(s.sequential()
.groupBy(keyMapper, valueMapper, mapFactory)
.parallel(s.maxThreadNum(), s.splitor(), s.asyncExecutor(), s.cancelUncompletedThreads()));
} else {
return of(s.groupBy(keyMapper, valueMapper, mapFactory));
}
}
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream> groupBy(final Function super Map.Entry, ? extends KK> keyMapper,
final Function super Map.Entry, ? extends VV> valueMapper) {
return of(s.groupBy(keyMapper, valueMapper));
}
/**
*
* @param keyMapper
* @param valueMapper
* @param mapFactory
* @return
* @see Collectors#toMultimap(Function, Function, Supplier)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream> groupBy(final Function super Map.Entry, ? extends KK> keyMapper,
final Function super Map.Entry, ? extends VV> valueMapper, final Supplier extends Map>> mapFactory) {
return of(s.groupBy(keyMapper, valueMapper, mapFactory));
}
/**
*
* @param downstream
* @return
* @see Collectors#groupingBy(Function, Collector)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final Collector super Map.Entry, A, D> downstream) {
final Function super Map.Entry, K> keyMapper = Fn.key();
return of(s.groupBy(keyMapper, downstream));
}
/**
*
* @param downstream
* @param mapFactory
* @return
* @see Collectors#groupingBy(Function, Collector)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final Collector super Map.Entry, A, D> downstream, final Supplier extends Map> mapFactory) {
final Function super Map.Entry, K> keyMapper = Fn.key();
return of(s.groupBy(keyMapper, downstream, mapFactory));
}
/**
*
* @param keyMapper
* @param downstream
* @param mapFactory
* @return
* @see Collectors#groupingBy(Function, Collector, Supplier)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final Function super Map.Entry, ? extends KK> keyMapper,
final Collector super Map.Entry, A, D> downstream) {
return of(s.groupBy(keyMapper, downstream));
}
/**
*
* @param keyMapper
* @param downstream
* @return
* @see Collectors#groupingBy(Function, Collector)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final Function super Map.Entry, ? extends KK> keyMapper,
final Collector super Map.Entry, A, D> downstream, final Supplier extends Map> mapFactory) {
return of(s.groupBy(keyMapper, downstream, mapFactory));
}
/**
*
* @param mergeFunction
* @return
*/
@SequentialOnly
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final BinaryOperator mergeFunction) {
final Function super Map.Entry, K> keyMapper = Fn.key();
final Function super Map.Entry, V> valueMapper = Fn.value();
if (isParallel()) {
return of(s.sequential()
.groupBy(keyMapper, valueMapper, mergeFunction)
.parallel(s.maxThreadNum(), s.splitor(), s.asyncExecutor(), s.cancelUncompletedThreads()));
} else {
return of(s.groupBy(keyMapper, valueMapper, mergeFunction));
}
}
/**
*
* @param mergeFunction
* @param mapFactory
* @return
*/
@SequentialOnly
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final BinaryOperator mergeFunction, final Supplier extends Map> mapFactory) {
final Function super Map.Entry, K> keyMapper = Fn.key();
final Function super Map.Entry, V> valueMapper = Fn.value();
if (isParallel()) {
return of(s.sequential()
.groupBy(keyMapper, valueMapper, mergeFunction, mapFactory)
.parallel(s.maxThreadNum(), s.splitor(), s.asyncExecutor(), s.cancelUncompletedThreads()));
} else {
return of(s.groupBy(keyMapper, valueMapper, mergeFunction, mapFactory));
}
}
/**
*
* @param keyMapper
* @param valueMapper
* @param mergeFunction
* @return
* @see Collectors#groupBy(Function, Function, BinaryOperator)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final Function super Map.Entry, ? extends KK> keyMapper,
final Function super Map.Entry, ? extends VV> valueMapper, final BinaryOperator mergeFunction) {
return of(s.groupBy(keyMapper, valueMapper, mergeFunction));
}
/**
*
* @param keyMapper
* @param valueMapper
* @param mergeFunction
* @param mapFactory
* @return
* @see Collectors#groupBy(Function, Function, BinaryOperator, Supplier)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream groupBy(final Function super Map.Entry, ? extends KK> keyMapper,
final Function super Map.Entry, ? extends VV> valueMapper, final BinaryOperator mergeFunction,
final Supplier extends Map> mapFactory) {
return of(s.groupBy(keyMapper, valueMapper, mergeFunction, mapFactory));
}
/**
*
* @param collapsible
* @return
* @see Stream#collapse(BiPredicate, Collector)
*/
@SequentialOnly
@IntermediateOp
public Stream> collapseByKey(final BiPredicate super K, ? super K> collapsible) {
return collapseByKey(collapsible, Collectors. toList());
}
/**
* Merge series of adjacent elements which satisfy the given predicate using
* the merger function and return a new stream.
*
*
* This method only runs sequentially, even in parallel stream.
*
* @param collapsible
* @param collector
* @return
*/
@SequentialOnly
@IntermediateOp
public Stream collapseByKey(final BiPredicate super K, ? super K> collapsible, final Collector super V, A, R> collector) {
final BiPredicate super Map.Entry, ? super Map.Entry> collapsible2 = (t, u) -> collapsible.test(t.getKey(), u.getKey());
final Function, V> mapper = Fn.value();
return s.collapse(collapsible2, Collectors.mapping(mapper, collector));
}
@Override
public Stream> split(int chunkSize) {
return s.split(chunkSize).map(EntryStream::of);
}
@Override
public Stream>> splitToList(int chunkSize) {
return s.splitToList(chunkSize);
}
@Override
public Stream> split(Predicate super Map.Entry> predicate) {
return s.split(predicate).map(EntryStream::of);
}
@Override
public Stream>> splitToList(Predicate super Map.Entry> predicate) {
return s.splitToList(predicate);
}
@Override
public Stream> splitAt(int where) {
return s.splitAt(where).map(EntryStream::of);
}
@Override
public Stream> splitAt(Predicate super Map.Entry> where) {
return s.splitAt(where).map(EntryStream::of);
}
@Override
public Stream> sliding(int windowSize, int increment) {
return s.sliding(windowSize, increment).map(EntryStream::of);
}
@Override
public Stream>> slidingToList(int windowSize, int increment) {
return s.slidingToList(windowSize, increment);
}
@Override
public EntryStream intersection(Collection> c) {
return of(s.intersection(c));
}
@Override
public EntryStream difference(Collection> c) {
return of(s.difference(c));
}
@Override
public EntryStream symmetricDifference(Collection> c) {
return of(s.symmetricDifference(c));
}
/**
* Compares keys and then compares values if key is equals.
*/
@SuppressWarnings("rawtypes")
@Override
@Deprecated
public EntryStream sorted() {
final Comparator> cmp = Comparators. comparingByKey((Comparator) Fn.naturalOrder())
.thenComparing(Comparators.comparingByValue((Comparator) Fn.naturalOrder()));
return of(s.sorted(cmp));
}
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream sorted(final Comparator super Map.Entry> comparator) {
return of(s.sorted(comparator));
}
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream sortedByKey(final Comparator super K> keyComparator) {
final Comparator> comparator = Comparators.comparingByKey(keyComparator);
return of(s.sorted(comparator));
}
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream sortedByValue(final Comparator super V> valueComparator) {
final Comparator> comparator = Comparators.comparingByValue(valueComparator);
return of(s.sorted(comparator));
}
@SuppressWarnings("rawtypes")
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream sortedBy(Function super Map.Entry, ? extends Comparable> keyMapper) {
return of(s.sortedBy(keyMapper));
}
/**
*
* @param keyMapper
* @return
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public EntryStream