mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
CollectorUtil 新增两个对toMap的重载,并将EasyStream中join采用CollectorUtil中的joining
This commit is contained in:
parent
6705274112
commit
056eb5ded6
@ -148,6 +148,34 @@ public class CollectorUtil {
|
||||
return groupingBy(classifier, Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对null友好的 toMap 操作的 {@link Collector}实现,默认使用HashMap
|
||||
*
|
||||
* @param keyMapper 指定map中的key
|
||||
* @param valueMapper 指定map中的value
|
||||
* @param <T> 实体类型
|
||||
* @param <K> map中key的类型
|
||||
* @param <U> map中value的类型
|
||||
* @return 对null友好的 toMap 操作的 {@link Collector}实现
|
||||
*/
|
||||
public static <T, K, U> Collector<T, ?, Map<K, U>> toMap(final Function<? super T, ? extends K> keyMapper,
|
||||
final Function<? super T, ? extends U> valueMapper) {
|
||||
return toMap(keyMapper, valueMapper, (l, r) -> r);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对null友好的 toMap 操作的 {@link Collector}实现,默认使用HashMap
|
||||
*
|
||||
* @param keyMapper 指定map中的key
|
||||
* @param <T> 实体类型
|
||||
* @param <K> map中key的类型
|
||||
* @return 对null友好的 toMap 操作的 {@link Collector}实现
|
||||
*/
|
||||
public static <T, K> Collector<T, ?, Map<K, T>> toMap(final Function<? super T, ? extends K> keyMapper) {
|
||||
return toMap(keyMapper, Function.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* 对null友好的 toMap 操作的 {@link Collector}实现,默认使用HashMap
|
||||
*
|
||||
|
@ -778,7 +778,7 @@ public class EasyStream<T> extends StreamWrapper<T, EasyStream<T>> implements St
|
||||
public String join(final CharSequence delimiter,
|
||||
final CharSequence prefix,
|
||||
final CharSequence suffix) {
|
||||
return map(String::valueOf).collect(Collectors.joining(delimiter, prefix, suffix));
|
||||
return map(String::valueOf).collect(CollectorUtil.joining(delimiter, prefix, suffix, Function.identity()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user