All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.bnd.stream.MapStream Maven / Gradle / Ivy

The newest version!
package aQute.bnd.stream;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.Function;
import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleBiFunction;
import java.util.function.ToIntBiFunction;
import java.util.function.ToLongBiFunction;
import java.util.stream.BaseStream;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public interface MapStream extends BaseStream, MapStream> {
	static  MapStream of(Map map) {
		return of(map.entrySet());
	}

	static  MapStream ofNullable(Map map) {
		return (map != null) ? of(map) : empty();
	}

	static  MapStream of(Collection> collection) {
		return of(collection.stream());
	}

	static  MapStream ofNullable(Collection> collection) {
		return (collection != null) ? of(collection) : empty();
	}

	static  MapStream of(Stream> stream) {
		return new EntryPipeline<>(stream);
	}

	static  MapStream ofNullable(Stream> stream) {
		return (stream != null) ? of(stream) : empty();
	}

	static  MapStream concat(MapStream a, MapStream b) {
		return of(Stream.concat(a.entries(), b.entries()));
	}

	static  MapStream empty() {
		return of(Stream.empty());
	}

	static  MapStream of(K k1, V v1) {
		return of(Stream.of(entry(k1, v1)));
	}

	static  MapStream of(K k1, V v1, K k2, V v2) {
		return ofEntries(entry(k1, v1), entry(k2, v2));
	}

	static  MapStream of(K k1, V v1, K k2, V v2, K k3, V v3) {
		return ofEntries(entry(k1, v1), entry(k2, v2), entry(k3, v3));
	}

	static  MapStream of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
		return ofEntries(entry(k1, v1), entry(k2, v2), entry(k3, v3), entry(k4, v4));
	}

	@SafeVarargs
	static  MapStream ofEntries(Entry... entries) {
		return of(Arrays.stream(entries));
	}

	static  MapStream ofEntries(Stream stream,
		Function> entryMapper) {
		return of(stream.map(entryMapper));
	}

	static  Entry entry(K key, V value) {
		return new SimpleImmutableEntry<>(key, value);
	}

	Stream> entries();

	Stream keys();

	Stream values();

	MapStream distinct();

	MapStream filter(BiPredicate filter);

	MapStream filterKey(Predicate filter);

	MapStream filterValue(Predicate filter);

	 MapStream map(BiFunction> mapper);

	 MapStream mapKey(Function mapper);

	 MapStream mapValue(Function mapper);

	 Stream mapToObj(BiFunction mapper);

	IntStream mapToInt(ToIntBiFunction mapper);

	LongStream mapToLong(ToLongBiFunction mapper);

	DoubleStream mapToDouble(ToDoubleBiFunction mapper);

	 MapStream flatMap(
		BiFunction> mapper);

	 MapStream flatMapKey(Function> mapper);

	 MapStream flatMapValue(Function> mapper);

	 Stream flatMapToObj(BiFunction> mapper);

	IntStream flatMapToInt(BiFunction mapper);

	LongStream flatMapToLong(BiFunction mapper);

	DoubleStream flatMapToDouble(BiFunction mapper);

	MapStream peek(BiConsumer peek);

	MapStream peekKey(Consumer peek);

	MapStream peekValue(Consumer peek);

	MapStream sorted();

	MapStream sorted(Comparator> comparator);

	MapStream sortedByKey();

	MapStream sortedByKey(Comparator comparator);

	MapStream sortedByValue();

	MapStream sortedByValue(Comparator comparator);

	MapStream limit(long maxSize);

	MapStream skip(long n);

	long count();

	void forEach(BiConsumer consumer);

	void forEachOrdered(BiConsumer consumer);

	boolean anyMatch(BiPredicate predicate);

	boolean allMatch(BiPredicate predicate);

	boolean noneMatch(BiPredicate predicate);

	 R collect(Supplier supplier, BiConsumer> accumulator,
		BiConsumer combiner);

	 R collect(Collector, A, R> collector);

	static  Collector, ?, Map> toMap() {
		return Collectors.toMap(Entry::getKey, Entry::getValue);
	}

	static  Collector, ?, Map> toMap(
		BinaryOperator mergeFunction) {
		return Collectors.toMap(Entry::getKey, Entry::getValue, mergeFunction);
	}

	static > Collector, ?, M> toMap(
		BinaryOperator mergeFunction, Supplier mapSupplier) {
		return Collectors.toMap(Entry::getKey, Entry::getValue, mergeFunction, mapSupplier);
	}

	Optional> max(Comparator> comparator);

	Optional> maxByKey(Comparator comparator);

	Optional> maxByValue(Comparator comparator);

	Optional> min(Comparator> comparator);

	Optional> minByKey(Comparator comparator);

	Optional> minByValue(Comparator comparator);

	Optional> findAny();

	Optional> findFirst();

	Entry[] toArray();

	MapStream takeWhile(BiPredicate predicate);

	MapStream takeWhileKey(Predicate predicate);

	MapStream takeWhileValue(Predicate predicate);

	MapStream dropWhile(BiPredicate predicate);

	MapStream dropWhileKey(Predicate predicate);

	MapStream dropWhileValue(Predicate predicate);

	 MapStream mapMulti(TriConsumer> mapper);

	 MapStream mapMultiKey(BiConsumer> mapper);

	 MapStream mapMultiValue(BiConsumer> mapper);

	 Stream mapMultiToObj(TriConsumer> mapper);

	IntStream mapMultiToInt(TriConsumer mapper);

	LongStream mapMultiToLong(TriConsumer mapper);

	DoubleStream mapMultiToDouble(TriConsumer mapper);

}