public class MoreStream extends Object
| 构造器和说明 |
|---|
MoreStream() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> boolean |
arrayContains(T[] array,
T element)
Check whether the given Array contains the given element.
|
static <X extends Throwable> |
checkWithThrow(boolean expression,
Function<String,X> exception,
String errorMessage,
Object... errorMessageArgs) |
static <X extends Throwable> |
checkWithThrow(boolean expression,
@NonNull Supplier<X> exception) |
static boolean |
containsAny(Object source,
Object... targets) |
static <T,U> List<U> |
convertList(Collection<T> from,
Function<T,U> func) |
static <T,U> List<U> |
convertList(Collection<T> from,
Function<T,U> func,
Predicate<T> filter) |
static <T,K> Map<K,T> |
convertMap(Collection<T> from,
Function<T,K> keyFunc) |
static <T,K,V> Map<K,V> |
convertMap(Collection<T> from,
Function<T,K> keyFunc,
Function<T,V> valueFunc) |
static <T,K,V> Map<K,V> |
convertMap(Collection<T> from,
Function<T,K> keyFunc,
Function<T,V> valueFunc,
BinaryOperator<V> mergeFunction) |
static <T,K,V> Map<K,V> |
convertMap(Collection<T> from,
Function<T,K> keyFunc,
Function<T,V> valueFunc,
BinaryOperator<V> mergeFunction,
Supplier<? extends Map<K,V>> supplier) |
static <T,K,V> Map<K,V> |
convertMap(Collection<T> from,
Function<T,K> keyFunc,
Function<T,V> valueFunc,
Supplier<? extends Map<K,V>> supplier) |
static <T,K> Map<K,T> |
convertMap(Collection<T> from,
Function<T,K> keyFunc,
Supplier<? extends Map<K,T>> supplier) |
static <T,U> Set<U> |
convertSet(Collection<T> from,
Function<T,U> func) |
static <T,U> Set<U> |
convertSet(Collection<T> from,
Function<T,U> func,
Predicate<T> filter) |
static <T,R> List<T> |
distinct(Collection<T> from,
Function<T,R> keyMapper) |
static <T,R> List<T> |
distinct(Collection<T> from,
Function<T,R> keyMapper,
BinaryOperator<T> cover) |
static <T> List<T> |
distinct(List<T> list) |
static <T> List<T> |
filterList(Collection<T> from,
Predicate<T> predicate) |
static <E> E |
findAny(List<E> list) |
static <T> T |
getFirst(List<T> list) |
static <T> T |
getFuture(CompletableFuture<T> future,
Consumer<? super Throwable> exceptionHandler)
返回Future结果
|
static <T> T |
getFuture(CompletableFuture<T> future,
Consumer<? super Throwable> exceptionHandler,
T defaultValue)
返回Future结果
|
static <T> T |
getFuture(CompletableFuture<T> future,
T defaultValue)
返回Future结果
|
static <T> T |
getFuture(Future<? extends T> future,
Duration duration) |
static <T> T |
getFuture(Future<? extends T> future,
long timeout,
TimeUnit unit) |
static <T> T |
getFuture(Future<? extends T> future,
long timeout,
TimeUnit unit,
boolean cancelOnTimeout)
获取并返回一个
Future的操作结果值,并将可能出现的异常以非检查异常的方式抛出 |
static <T> T |
getLast(List<T> list) |
static <K,V> V |
getMapValue(Map<K,V> map,
K key) |
static <K,V> Map<K,V> |
getMapValues(Map<K,V> map,
K... key) |
static <T,K> Map<K,List<T>> |
groupBy(Collection<T> list,
Function<? super T,? extends K> func)
分组数据统计
|
static boolean |
isAnyEmpty(Collection<?>... collections) |
static <K,V> Map<K,List<V>> |
keyMerged(Map<K,List<V>> target,
Map<K,List<V>>... maps)
进行map集合中相同元素的value值聚合
|
static <T> List<T> |
limit(List<T> list,
int size)
集合获取前边几个元素
|
static <T> List<T> |
listMerge(Collection<T>... coll)
集合元素合并
|
static <K,V> ConcurrentHashMap<K,V> |
ofConcurrentHashMap(Object... keysValues)
键值对转换为并发HashMap
|
static <E> List<E> |
ofImmutableList(E... es)
数组元素转List集合
|
static <E> Set<E> |
ofImmutableSet(E... es)
数组元素转SET集合
|
static <T> Stream<List<T>> |
partition(Stream<T> stream,
int size)
将一个Stream按一定的大小进行批次分组,返回一个按组的新的Stream
|
static <T> List<T> |
randomList(Collection<T> list)
打散集合
|
static <T> List<T> |
randomList(List<T> list,
int size)
带数量获取随机子集
|
static <T,R> List<R> |
supplyList(@NonNull Supplier<Collection<T>> supplier,
@NonNull Function<T,? extends R> mapper)
批量数据处理
|
static <T,R> R |
supplyOne(@NonNull Supplier<T> supplier,
@NonNull Function<T,? extends R> mapper)
单体数据处理
|
static <T,R> List<R> |
toList(Collection<T> coll,
Function<? super T,? extends R> mapper)
从目标集合中抽取指定字段并去重
|
static <T,R> List<R> |
toListWithDistinct(Collection<T> coll,
Function<? super T,? extends R> mapper)
从目标集合中抽取指定字段并去重
|
static <T,K,V> Map<K,V> |
toMap(Collection<T> coll,
Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
讲目标list集合转换为map
|
public static <T> T getFirst(List<T> list)
public static <T> T getLast(List<T> list)
public static <E> E findAny(List<E> list)
public static boolean isAnyEmpty(Collection<?>... collections)
public static <T> List<T> filterList(Collection<T> from, Predicate<T> predicate)
@SafeVarargs public static <E> Set<E> ofImmutableSet(E... es)
E - 泛型es - 数组元素@SafeVarargs public static <E> List<E> ofImmutableList(E... es)
E - 泛型es - 数组元素public static <T,K> Map<K,List<T>> groupBy(Collection<T> list, Function<? super T,? extends K> func)
T - Key泛型K - 集合泛型list - 原始集合func - 分组字段public static <T> List<T> limit(List<T> list, int size)
T - 泛型支持list - 目标集合size - 目标数量public static <T,R> List<T> distinct(Collection<T> from, Function<T,R> keyMapper)
public static <T,R> List<T> distinct(Collection<T> from, Function<T,R> keyMapper, BinaryOperator<T> cover)
public static <T,U> List<U> convertList(Collection<T> from, Function<T,U> func)
public static <T,U> List<U> convertList(Collection<T> from, Function<T,U> func, Predicate<T> filter)
public static <T,U> Set<U> convertSet(Collection<T> from, Function<T,U> func)
public static <T,U> Set<U> convertSet(Collection<T> from, Function<T,U> func, Predicate<T> filter)
public static <T,K> Map<K,T> convertMap(Collection<T> from, Function<T,K> keyFunc)
public static <T,K> Map<K,T> convertMap(Collection<T> from, Function<T,K> keyFunc, Supplier<? extends Map<K,T>> supplier)
public static <T,K,V> Map<K,V> convertMap(Collection<T> from, Function<T,K> keyFunc, Function<T,V> valueFunc)
public static <T,K,V> Map<K,V> convertMap(Collection<T> from, Function<T,K> keyFunc, Function<T,V> valueFunc, BinaryOperator<V> mergeFunction)
public static <T,K,V> Map<K,V> convertMap(Collection<T> from, Function<T,K> keyFunc, Function<T,V> valueFunc, Supplier<? extends Map<K,V>> supplier)
public static <T,K,V> Map<K,V> convertMap(Collection<T> from, Function<T,K> keyFunc, Function<T,V> valueFunc, BinaryOperator<V> mergeFunction, Supplier<? extends Map<K,V>> supplier)
public static <T> List<T> randomList(Collection<T> list)
T - 泛型list - 原始数据集public static <T> List<T> randomList(List<T> list, int size)
T - 泛型list - 原始数据集size - 目标数量@SafeVarargs public static <T> List<T> listMerge(Collection<T>... coll)
T - 泛型支持coll - 多个目标集合@SafeVarargs public static <K,V> Map<K,List<V>> keyMerged(Map<K,List<V>> target, Map<K,List<V>>... maps)
K - 泛型约束KeyV - 泛型约束Maptarget - 目标Mapmaps - 往目标Map上追加的多个Mappublic static <T> boolean arrayContains(@Nullable
T[] array,
T element)
T - The generic tagarray - the Array to checkelement - the element to look fortrue if found, false elsepublic static <T,R> List<R> toList(Collection<T> coll, Function<? super T,? extends R> mapper)
T - 原始集合元素类型R - 目标结果元素类型coll - 原始集合mapper - 字段抽取public static <T,R> List<R> toListWithDistinct(Collection<T> coll, Function<? super T,? extends R> mapper)
T - 原始集合元素类型R - 目标结果元素类型coll - 原始集合mapper - 字段抽取@SafeVarargs public static <K,V> Map<K,V> getMapValues(Map<K,V> map, K... key)
public static <K,V> V getMapValue(Map<K,V> map, K key)
public static <T,K,V> Map<K,V> toMap(Collection<T> coll, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)
T - 原始集合元素类型K - 目标集合Key类型V - 目标集合Value类型coll - 原始集合keyMapper - key处理valueMapper - map处理public static <K,V> ConcurrentHashMap<K,V> ofConcurrentHashMap(Object... keysValues)
K - key泛型V - value泛型keysValues - 键值对public static <T> Stream<List<T>> partition(Stream<T> stream, int size)
T - 输入值的类型泛型stream - 输入值的Streamsize - 分组的大小Streampublic static <T,R> R supplyOne(@NonNull
@NonNull Supplier<T> supplier,
@NonNull
@NonNull Function<T,? extends R> mapper)
T - 供给输出类型R - 结果数据类型supplier - 数据供给mapper - 数据转换public static <T,R> List<R> supplyList(@NonNull @NonNull Supplier<Collection<T>> supplier, @NonNull @NonNull Function<T,? extends R> mapper)
T - 供给输出类型R - 结果数据类型supplier - 数据供给mapper - 数据转换public static <T> T getFuture(CompletableFuture<T> future, Consumer<? super Throwable> exceptionHandler)
T - 返回结果类型future - 要获取值的FutureexceptionHandler - 异常抛出public static <T> T getFuture(CompletableFuture<T> future, T defaultValue)
T - 返回结果类型future - 要获取值的FuturedefaultValue - 发生异常时返回的兜底值public static <T> T getFuture(CompletableFuture<T> future, Consumer<? super Throwable> exceptionHandler, T defaultValue)
T - 返回结果类型future - 要获取值的FutureexceptionHandler - 异常处理defaultValue - 发生异常时返回的兜底值public static <X extends Throwable> void checkWithThrow(boolean expression, @NonNull @NonNull Supplier<X> exception) throws X extends Throwable
X extends Throwablepublic static <X extends Throwable> void checkWithThrow(boolean expression, Function<String,X> exception, String errorMessage, Object... errorMessageArgs) throws X extends Throwable
X extends Throwablepublic static <T> T getFuture(@Nonnull Future<? extends T> future, @Nonnull Duration duration)
public static <T> T getFuture(@Nonnull Future<? extends T> future, @Nonnegative long timeout, @Nonnull TimeUnit unit)
public static <T> T getFuture(@Nonnull Future<? extends T> future, @Nonnegative long timeout, @Nonnull TimeUnit unit, boolean cancelOnTimeout)
Future的操作结果值,并将可能出现的异常以非检查异常的方式抛出T - 返回结果类型future - 要获取值的Futuretimeout - 超时时间unit - 超时时间单位cancelOnTimeout - 执行超时后是否取消Future的执行com.google.common.util.concurrent.UncheckedTimeoutException - 操作超时异常CancellationException - 任务取消异常com.google.common.util.concurrent.ExecutionError - 执行时发生的Error异常com.google.common.util.concurrent.UncheckedExecutionException - 其他执行异常Copyright © 2023 wuyushuo. All rights reserved.