MapStream implements Stream<Map.Entry<K, V>> { public <R> MapStream<R, V> flatMapKey(BiFunction<? super K, ? super V, ? extends Stream<? extends R>> mapper) { requireNonNull(mapper); return new MapStream<>(inner.flatMap(e -> mapper.apply(e.getKey(), e.getValue()) .map(k -> new AbstractMap.SimpleEntry<>( k, e.getValue() ) ) )); } private  MapStream(Stream<Map.Entry<K, V>> inner); static MapStream<K, V> of(Map.Entry<K, V> entry); @SafeVarargs // Creating a Stream of an array is safe. @SuppressWarnings({"unchecked", "varargs"}) static MapStream<K, V> of(Map.Entry<K, V>... entries); static MapStream<K, V> of(Map<K, V> map); static MapStream<K, V> of(Map<K, V> map, boolean parallel); static MapStream<K, V> of(Stream<Map.Entry<K, V>> stream); static MapStream<K, V> fromKeys(Stream<K> keys, Function<K, V> valueFromKey); static MapStream<K, V> fromValues(Stream<V> values, Function<V, K> keyFromValue); static MapStream<K, V> fromStream(Stream<E> stream, Function<E, K> keyMapper, Function<E, V> valueMapper); static MapStream<K, V> empty(); static MapStream<V, K> flip(MapStream<K, V> original); @Override MapStream<K, V> filter(Predicate<? super Map.Entry<K, V>> predicate); MapStream<K, V> filter(BiPredicate<? super K, ? super V> predicate); MapStream<K, V> filterKey(Predicate<? super K> predicate); MapStream<K, V> filterValue(Predicate<? super V> predicate); @Override Stream<R> map(Function<? super Map.Entry<K, V>, ? extends R> mapper); Stream<R> map(BiFunction<? super K, ? super V, ? extends R> mapper); MapStream<R, V> mapKey(BiFunction<? super K, ? super V, ? extends R> mapper); MapStream<R, V> mapKey(Function<? super K, ? extends R> mapper); MapStream<K, R> mapValue(BiFunction<? super K, ? super V, ? extends R> mapper); MapStream<K, R> mapValue(Function<? super V, ? extends R> mapper); @Override IntStream mapToInt(ToIntFunction<? super Map.Entry<K, V>> mapper); IntStream mapToInt(ToIntBiFunction<? super K, ? super V> mapper); @Override LongStream mapToLong(ToLongFunction<? super Map.Entry<K, V>> mapper); LongStream mapToLong(ToLongBiFunction<? super K, ? super V> mapper); @Override DoubleStream mapToDouble(ToDoubleFunction<? super Map.Entry<K, V>> mapper); DoubleStream mapToDouble(ToDoubleBiFunction<? super K, ? super V> mapper); @Override Stream<R> flatMap(Function<? super Map.Entry<K, V>, ? extends Stream<? extends R>> mapper); Stream<R> flatMap(BiFunction<? super K, ? super V, ? extends Stream<? extends R>> mapper); MapStream<R, V> flatMapKey(BiFunction<? super K, ? super V, ? extends Stream<? extends R>> mapper); MapStream<R, V> flatMapKey(Function<? super K, ? extends Stream<? extends R>> mapper); MapStream<K, R> flatMapValue(BiFunction<? super K, ? super V, ? extends Stream<? extends R>> mapper); MapStream<K, R> flatMapValue(Function<? super V, ? extends Stream<? extends R>> mapper); @Override IntStream flatMapToInt(Function<? super Map.Entry<K, V>, ? extends IntStream> mapper); IntStream flatMapToInt(BiFunction<? super K, ? super V, ? extends IntStream> mapper); @Override LongStream flatMapToLong(Function<? super Map.Entry<K, V>, ? extends LongStream> mapper); LongStream flatMapToLong(BiFunction<? super K, ? super V, ? extends LongStream> mapper); @Override DoubleStream flatMapToDouble(Function<? super Map.Entry<K, V>, ? extends DoubleStream> mapper); DoubleStream flatMapToDouble(BiFunction<? super K, ? super V, ? extends DoubleStream> mapper); Stream<K> keys(); Stream<V> values(); @Override MapStream<K, V> distinct(); MapStream<K, V> distinctKeys(); MapStream<K, V> distinctValues(); MapStream<K, V> distinctKeys(BinaryOperator<V> merger); MapStream<K, V> distinctValues(BinaryOperator<K> merger); @Override MapStream<K, V> sorted(); @Override MapStream<K, V> sorted(Comparator<? super Map.Entry<K, V>> comparator); MapStream<K, V> sortedByKey(Comparator<K> comparator); MapStream<K, V> sortedByValue(Comparator<V> comparator); @Override MapStream<K, V> peek(Consumer<? super Map.Entry<K, V>> action); MapStream<K, V> peek(BiConsumer<? super K, ? super V> action); @Override MapStream<K, V> limit(long maxSize); @Override MapStream<K, V> skip(long n); @Override void forEach(Consumer<? super Map.Entry<K, V>> action); void forEach(BiConsumer<? super K, ? super V> action); @Override void forEachOrdered(Consumer<? super Map.Entry<K, V>> action); void forEachOrdered(BiConsumer<? super K, ? super V> action); @Override Object[] toArray(); @Override A[] toArray(IntFunction<A[]> generator); @Override Map.Entry<K, V> reduce(Map.Entry<K, V> identity, BinaryOperator<Map.Entry<K, V>> accumulator); @Override Optional<Map.Entry<K, V>> reduce(BinaryOperator<Map.Entry<K, V>> accumulator); @Override U reduce(U identity, BiFunction<U, ? super Map.Entry<K, V>, U> accumulator, BinaryOperator<U> combiner); @Override R collect(Supplier<R> supplier, BiConsumer<R, ? super Map.Entry<K, V>> accumulator, BiConsumer<R, R> combiner); @Override R collect(Collector<? super Map.Entry<K, V>, A, R> collector); MapStream<K2, List<V>> groupingBy(Function<V, K2> grouper); @Override Optional<Map.Entry<K, V>> min(Comparator<? super Map.Entry<K, V>> comparator); Optional<Map.Entry<K, V>> minByKey(Comparator<K> comparator); Optional<Map.Entry<K, V>> minByValue(Comparator<V> comparator); @Override Optional<Map.Entry<K, V>> max(Comparator<? super Map.Entry<K, V>> comparator); Optional<Map.Entry<K, V>> maxByKey(Comparator<K> comparator); Optional<Map.Entry<K, V>> maxByValue(Comparator<V> comparator); @Override long count(); @Override boolean anyMatch(Predicate<? super Map.Entry<K, V>> predicate); boolean anyMatch(BiPredicate<? super K, ? super V> predicate); @Override boolean allMatch(Predicate<? super Map.Entry<K, V>> predicate); boolean allMatch(BiPredicate<? super K, ? super V> predicate); @Override boolean noneMatch(Predicate<? super Map.Entry<K, V>> predicate); boolean noneMatch(BiPredicate<? super K, ? super V> predicate); @Override Optional<Map.Entry<K, V>> findFirst(); @Override Optional<Map.Entry<K, V>> findAny(); @Override Iterator<Map.Entry<K, V>> iterator(); @Override Spliterator<Map.Entry<K, V>> spliterator(); @Override boolean isParallel(); @Override MapStream<K, V> sequential(); @Override MapStream<K, V> parallel(); @Override MapStream<K, V> unordered(); @Override MapStream<K, V> onClose(Runnable closeHandler); @Override void close(); Map<K, V> toMap(); Map<K, V> toMap(BinaryOperator<V> mergeFunction); Map<K, V> toConcurrentMap(); Map<K, V> toConcurrentMap(BinaryOperator<V> mergeFunction); SortedMap<K, V> toSortedMap(); SortedMap<K, V> toSortedMapByKey(Comparator<K> keyComparator); SortedMap<K, V> toSortedMap(BinaryOperator<V> mergeFunction); SortedMap<K, V> toSortedMap(Comparator<K> keyComparator, BinaryOperator<V> mergeFunction); ConcurrentNavigableMap<K, V> toConcurrentNavigableMap(); ConcurrentNavigableMap<K, V> toConcurrentNavigableMapByKey(Comparator<K> keyComparator); ConcurrentNavigableMap<K, V> toConcurrentNavigableMap(BinaryOperator<V> mergeFunction); ConcurrentNavigableMap<K, V> toConcurrentNavigableMap(Comparator<K> keyComparator, BinaryOperator<V> mergeFunction); List<Map.Entry<K, V>> toList(); @SuppressWarnings("varargs") @SafeVarargs // Iterating over an array is safe. static Comparator<K> comparing(Function<K, ? extends Comparable<?>>... methods); static BinaryOperator<T> throwingMerger();  }
@Test void flatMapKey() { final long expected = refStream().flatMap(e -> e.getKey().chars().boxed()).count(); final long actual = instance.flatMapKey(e -> e.chars().boxed()).count(); assertEquals(expected, actual); }
@Test void testFlatMapKey() { final long expected = refStream().flatMap(e -> e.getKey().chars().boxed()).count(); final long actual = instance.flatMapKey((k, v) -> k.chars().boxed()).count(); assertEquals(expected, actual); }