K - 键类型V - 值类型public class EntryStream<K,V> extends AbstractEnhancedWrappedStream<Map.Entry<K,V>,EntryStream<K,V>>
参考StreamEx的EntryStream与vavr的Map,是针对键值对对象Map.Entry特化的单元素增强流实现。
本身可视为一个元素类型为Map.Entry的Stream,
用于支持流式处理Map集合中的、或其他键值对类型的数据。
Stream.Builder<T>streamNOT_FOUND_ELEMENT_INDEX| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(BiPredicate<? super K,? super V> predicate)
所有键值对是否都符合条件
|
boolean |
anyMatch(BiPredicate<? super K,? super V> predicate)
是否存在任意符合条件的键值对
|
EntryStream<K,V> |
append(Iterable<? extends Map.Entry<K,V>> entries)
将输入元素转为流,返回一个前半段为当前流,后半段为新流的新
EasyStream实例 |
<R> R |
collectKeys(Collector<K,?,R> collector)
收集键
|
<R> R |
collectValues(Collector<V,?,R> collector)
收集值
|
EntryStream<K,V> |
distinctByKey()
根据键去重,默认丢弃靠后的
|
EntryStream<K,V> |
distinctByValue()
根据值去重,默认丢弃靠后的
|
static <K,V> EntryStream<K,V> |
empty()
创建一个空的串行流
|
EntryStream<K,V> |
filter(BiPredicate<? super K,? super V> filter)
根据键和值过滤键值对
|
EntryStream<K,V> |
filterByKey(Predicate<? super K> filter)
根据键过滤键值对
|
EntryStream<K,V> |
filterByValue(Predicate<? super V> filter)
根据值过滤键值对
|
<R> EasyStream<R> |
flatMap(Function<? super Map.Entry<K,V>,? extends Stream<? extends R>> mapper)
扩散流操作,可能影响流元素个数,将原有流元素执行mapper操作,返回多个流所有元素组成的流
这是一个无状态中间操作 例如,将users里所有user的id和parentId组合在一起,形成一个新的流:
FastStream<Long> ids = FastStream.of(users).flatMap(user -> FastStream.of(user.getId(), user.getParentId()));
|
<N> EntryStream<N,V> |
flatMapKey(Function<? super K,Stream<? extends N>> keyMapper)
将原有流的键执行mapper操作映射为流,流中的所有所有元素仍然对应原本的值,
然后再返回由这些流中所有元素组成的流新
EntryStream串行流。 |
<N> EntryStream<K,N> |
flatMapValue(Function<? super V,Stream<? extends N>> valueMapper)
将原有流的值执行mapper操作映射为流,流中的所有所有元素仍然对应原本的键,
然后再返回由这些流中所有元素组成的流新
EntryStream串行流。 |
void |
forEach(BiConsumer<K,V> consumer)
遍历键值对
|
Map<K,List<V>> |
groupByKey()
将键值对按键分组
|
<C extends Collection<V>> |
groupByKey(Collector<V,?,C> collector)
将键值对按键分组
|
<C extends Collection<V>,M extends Map<K,C>> |
groupByKey(Supplier<M> mapFactory,
Collector<V,?,C> collector)
将键值对按键分组
|
EntryStream<V,K> |
inverse()
将键值对翻转
|
<N> EasyStream<N> |
map(BiFunction<? super K,? super V,? extends N> mapper)
将实例转为根据键值对生成的单对象
Stream实例 |
<R> EasyStream<R> |
map(Function<? super Map.Entry<K,V>,? extends R> mapper)
返回与指定函数将元素作为参数执行的结果组成的流
这是一个无状态中间操作
|
<N> EntryStream<N,V> |
mapKeys(Function<? super K,? extends N> mapper)
将键映射为另一类型
|
<N> EntryStream<K,N> |
mapValues(Function<? super V,? extends N> mapper)
将值映射为另一类型
|
static <K,V> EntryStream<K,V> |
merge(Iterable<K> keys,
Iterable<V> values)
根据键与值的集合创建键值对流,若两集合在相同下标的位置找不到对应的键或值,则使用
null填充。 |
boolean |
noneMatch(BiPredicate<? super K,? super V> predicate)
所有键值对是否都不符合条件
|
EntryStream<K,V> |
nonNullKey()
过滤流中键值对本身,或键值对的键为
null的元素 |
EntryStream<K,V> |
nonNullKeyValue()
过滤流中键值对本身、键值对中的值或键为
null的元素 |
EntryStream<K,V> |
nonNullValue()
过滤流中键值对本身,或键值对的值为
null的元素 |
static <K,V> EntryStream<K,V> |
of(Iterable<? extends Map.Entry<K,V>> entries)
|
static <T,K,V> EntryStream<K,V> |
of(Iterable<T> source,
Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
根据一个
Collection集合中创建一个串行流 |
static <K,V> EntryStream<K,V> |
of(Map<K,V> map)
根据一个
Map集合中的键值对创建一个串行流,
对流的操作不会影响到入参的map实例本身 |
static <K,V> EntryStream<K,V> |
of(Stream<? extends Map.Entry<K,V>> stream)
包装一个已有的流,若入参为空则返回一个空的串行流。
|
EntryStream<K,V> |
peekKey(Consumer<? super K> consumer)
检查键
|
EntryStream<K,V> |
peekValue(Consumer<? super V> consumer)
检查值
|
EntryStream<K,V> |
prepend(Iterable<? extends Map.Entry<K,V>> entries)
将输入元素转为流,返回一个前半段为新流,后半段为当前流的新
EasyStream实例 |
EntryStream<K,V> |
push(K key,
V value)
向当前流末尾追加元素
|
EntryStream<K,V> |
sortByKey(Comparator<? super K> comparator)
根据键排序
|
EntryStream<K,V> |
sortByValue(Comparator<? super V> comparator)
根据值排序
|
EasyStream<K> |
toKeyStream()
转为键的流
|
Map<K,V> |
toMap()
转为
HashMap集合 |
Map<K,V> |
toMap(Supplier<Map<K,V>> mapFactory)
转为
Map集合 |
Map<K,V> |
toMap(Supplier<Map<K,V>> mapFactory,
BinaryOperator<V> operator)
转为
Map集合 |
<N> Table<N,K,V> |
toTable(BiFunction<? super K,? super V,? extends N> rowKeyMapper)
|
<N> Table<N,K,V> |
toTable(BiFunction<? super K,? super V,? extends N> rowKeyMapper,
Supplier<Map<K,V>> colMapFactory,
BinaryOperator<V> operator)
|
<N> Table<N,K,V> |
toTableByKey(Function<? super K,? extends N> rowKeyMapper)
|
<N> Table<N,K,V> |
toTableByKey(Function<? super K,? extends N> rowKeyMapper,
Supplier<Map<K,V>> colMapFactory,
BinaryOperator<V> operator)
|
<N> Table<N,K,V> |
toTableByValue(Function<? super V,? extends N> rowKeyMapper)
|
<N> Table<N,K,V> |
toTableByValue(Function<? super V,? extends N> rowKeyMapper,
Supplier<Map<K,V>> colMapFactory,
BinaryOperator<V> operator)
|
EasyStream<V> |
toValueStream()
转为值的流
|
EntryStream<K,V> |
unshift(K key,
V value)
项当前流队首追加元素
|
EntryStream<K,V> |
wrap(Stream<Map.Entry<K,V>> stream)
根据一个原始的流,返回一个新包装类实例
|
equals, exec, hashCode, toString, unwrapclone, finalize, getClass, notify, notifyAll, wait, wait, waitat, findFirst, findFirstIdx, findLast, findLast, findLastIdx, forEachIdx, forEachOrderedIdx, group, group, group, isEmpty, isNotEmpty, join, join, join, partition, partition, partition, toColl, toIdxMap, toIdxMap, toList, toMap, toMap, toMap, toMap, toSet, toUnmodifiableList, toUnmodifiableMap, toUnmodifiableMap, toUnmodifiableSet, toZipdistinct, dropWhile, filter, filterIdx, flat, flat, flatMapIdx, flatNonNull, flatTree, log, mapIdx, mapMulti, mapNonNull, nonNull, parallel, peekIdx, push, reverse, splice, split, splitList, takeWhile, toEntries, toEntries, unshift, zipallMatch, anyMatch, close, collect, collect, count, distinct, easyStream, filter, findAny, findFirst, flatMapToDouble, flatMapToInt, flatMapToLong, forEach, forEachOrdered, isParallel, iterator, limit, mapToDouble, mapToInt, mapToLong, max, min, noneMatch, onClose, parallel, peek, reduce, reduce, reduce, sequential, skip, sorted, sorted, spliterator, toArray, toArray, unorderedpublic static <K,V> EntryStream<K,V> merge(Iterable<K> keys, Iterable<V> values)
null填充。[1, 2, 3]与[1, 2]合并,则得到[{1=1}, {2=2}, {3=null}]。K - 键类型V - 值类型keys - 键集合values - 值集合EntryStream实例public static <K,V> EntryStream<K,V> of(Map<K,V> map)
Map集合中的键值对创建一个串行流,
对流的操作不会影响到入参的map实例本身K - 键类型V - 值类型map - 集合EntryStream实例public static <K,V> EntryStream<K,V> of(Iterable<? extends Map.Entry<K,V>> entries)
K - 键类型V - 值类型entries - Iterable实例EntryStream实例public static <T,K,V> EntryStream<K,V> of(Iterable<T> source, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)
Collection集合中创建一个串行流T - 元素类型K - 键类型V - 值类型source - 原始集合keyMapper - 键的映射方法valueMapper - 值的映射方法EntryStream实例public static <K,V> EntryStream<K,V> of(Stream<? extends Map.Entry<K,V>> stream)
null,则会映射为一个键值皆为null的键值对。K - 键类型V - 值类型stream - 流EntryStream实例public static <K,V> EntryStream<K,V> empty()
K - 键类型V - 值类型EntryStream实例public EntryStream<K,V> distinctByKey()
EntryStream实例public EntryStream<K,V> distinctByValue()
EntryStream实例public EntryStream<K,V> filter(BiPredicate<? super K,? super V> filter)
filter - 判断条件EntryStream实例public EntryStream<K,V> filterByKey(Predicate<? super K> filter)
filter - 判断条件EntryStream实例public EntryStream<K,V> filterByValue(Predicate<? super V> filter)
filter - 判断条件EntryStream实例public EntryStream<K,V> nonNullKeyValue()
null的元素EntryStream实例public EntryStream<K,V> nonNullKey()
null的元素EntryStream实例public EntryStream<K,V> nonNullValue()
null的元素EntryStream实例public EntryStream<K,V> peekKey(Consumer<? super K> consumer)
consumer - 操作EntryStream实例public EntryStream<K,V> peekValue(Consumer<? super V> consumer)
consumer - 操作EntryStream实例public EntryStream<K,V> sortByKey(Comparator<? super K> comparator)
comparator - 排序器EntryStream实例public EntryStream<K,V> sortByValue(Comparator<? super V> comparator)
comparator - 排序器EntryStream实例public EntryStream<K,V> push(K key, V value)
key - 键value - 值EntryStream实例public EntryStream<K,V> unshift(K key, V value)
key - 键value - 值EntryStream实例public EntryStream<K,V> append(Iterable<? extends Map.Entry<K,V>> entries)
EasyStream实例entries - 键值对EntryStream实例public EntryStream<K,V> prepend(Iterable<? extends Map.Entry<K,V>> entries)
EasyStream实例entries - 键值对EntryStream实例public EasyStream<V> toValueStream()
public EasyStream<K> toKeyStream()
public <N> EntryStream<N,V> mapKeys(Function<? super K,? extends N> mapper)
N - 新的键类型mapper - 映射方法EntryStream实例public <N> EntryStream<K,N> mapValues(Function<? super V,? extends N> mapper)
N - 新的值类型mapper - 映射方法EntryStream实例public <R> EasyStream<R> map(Function<? super Map.Entry<K,V>,? extends R> mapper)
R - 函数执行后返回流中元素的类型mapper - 指定的函数public <N> EasyStream<N> map(BiFunction<? super K,? super V,? extends N> mapper)
Stream实例N - 函数执行后返回流中元素的类型mapper - 映射方法public <R> EasyStream<R> flatMap(Function<? super Map.Entry<K,V>,? extends Stream<? extends R>> mapper)
FastStream<Long> ids = FastStream.of(users).flatMap(user -> FastStream.of(user.getId(), user.getParentId()));
R - 拆分后流的元素类型mapper - 操作,返回流public <N> EntryStream<N,V> flatMapKey(Function<? super K,Stream<? extends N>> keyMapper)
将原有流的键执行mapper操作映射为流,流中的所有所有元素仍然对应原本的值,
然后再返回由这些流中所有元素组成的流新EntryStream串行流。
效果类似:
// unwrap = [{a = 1}, {b = 2}, {c = 3}]
unwrap.flatMapKey(key -> Stream.of(key + "1", key + "2"));
// unwrap = [{a1 = 1}, {a2 = 1}, {b1 = 2}, {b2 = 2}, {c1 = 3}, {c2 = 3}]
N - 新的键类型keyMapper - 值转映射方法public <N> EntryStream<K,N> flatMapValue(Function<? super V,Stream<? extends N>> valueMapper)
将原有流的值执行mapper操作映射为流,流中的所有所有元素仍然对应原本的键,
然后再返回由这些流中所有元素组成的流新EntryStream串行流。
效果类似:
// unwrap = [{a = 1}, {b = 2}, {c = 3}]
unwrap.flatMapValue(num -> Stream.of(num, num+1));
// unwrap = [{a = 1}, {a = 2}, {b = 2}, {b = 3}, {c = 3}, {c = 4}]
N - 新的值类型valueMapper - 值转映射方法public Map<K,V> toMap(Supplier<Map<K,V>> mapFactory, BinaryOperator<V> operator)
Map集合mapFactory - 获取集合的工厂方法operator - 当存在重复键时的处理Collectors.toMap(Function, Function, BinaryOperator, Supplier)public Map<K,V> toMap(Supplier<Map<K,V>> mapFactory)
Map集合mapFactory - 获取集合的工厂方法Collectors.toMap(Function, Function, BinaryOperator)public Map<K,V> toMap()
HashMap集合IllegalArgumentException - 当键重复时抛出Collectors.toMap(Function, Function)public <N> Table<N,K,V> toTable(BiFunction<? super K,? super V,? extends N> rowKeyMapper, Supplier<Map<K,V>> colMapFactory, BinaryOperator<V> operator)
N - 父集合的键类型rowKeyMapper - 将键映射为父集合中键的方法colMapFactory - 创建子集合的工厂方法operator - 当存在重复键时的处理Collectors.groupingBy(Function, Supplier, Collector)public <N> Table<N,K,V> toTable(BiFunction<? super K,? super V,? extends N> rowKeyMapper)
N - 父集合的键类型rowKeyMapper - 创建父集合的工厂方法IllegalArgumentException - 当父集合或子集合中的键重复时抛出public <N> Table<N,K,V> toTableByKey(Function<? super K,? extends N> rowKeyMapper, Supplier<Map<K,V>> colMapFactory, BinaryOperator<V> operator)
N - 父集合的键类型rowKeyMapper - 将键映射为父集合中键的方法colMapFactory - 创建子集合的工厂方法operator - 当存在重复键时的处理public <N> Table<N,K,V> toTableByKey(Function<? super K,? extends N> rowKeyMapper)
N - 父集合的键类型rowKeyMapper - 创建父集合的工厂方法IllegalArgumentException - 当父集合或子集合中的键重复时抛出public <N> Table<N,K,V> toTableByValue(Function<? super V,? extends N> rowKeyMapper, Supplier<Map<K,V>> colMapFactory, BinaryOperator<V> operator)
N - 父集合的键类型rowKeyMapper - 将键映射为父集合中键的方法colMapFactory - 创建子集合的工厂方法operator - 当存在重复键时的处理public <N> Table<N,K,V> toTableByValue(Function<? super V,? extends N> rowKeyMapper)
N - 父集合的键类型rowKeyMapper - 创建父集合的工厂方法IllegalArgumentException - 当父集合或子集合中的键重复时抛出public <C extends Collection<V>> Map<K,C> groupByKey(Collector<V,?,C> collector)
C - 值集合的类型collector - 对具有相同键的值的收集器public <C extends Collection<V>,M extends Map<K,C>> M groupByKey(Supplier<M> mapFactory, Collector<V,?,C> collector)
C - 值集合的类型M - 返回的map集合类型mapFactory - 创建map集合的工厂方法collector - 对具有相同键的值的收集器public void forEach(BiConsumer<K,V> consumer)
consumer - 操作public EntryStream<V,K> inverse()
EntryStream实例public <R> R collectKeys(Collector<K,?,R> collector)
R - 返回值类型collector - 收集器public <R> R collectValues(Collector<V,?,R> collector)
R - 返回值类型collector - 收集器public boolean anyMatch(BiPredicate<? super K,? super V> predicate)
predicate - 判断条件public boolean allMatch(BiPredicate<? super K,? super V> predicate)
predicate - 判断条件public boolean noneMatch(BiPredicate<? super K,? super V> predicate)
predicate - 判断条件Copyright © 2025. All rights reserved.