java.lang.Object
develop.toolkit.base.utils.CollectionAdvice
集合增强工具
- Author:
- qiushui on 2018-12-20.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> booleanallAccept(Collection<E> collection, Function<E, ?> function) 判断所有元素的处理值相等static <E> booleanallMatch(Collection<E> collection, Predicate<E> predicate) 全部匹配static <E> booleananyMatch(Collection<E> collection, Predicate<E> predicate) 任意一个匹配static <E,T> ListInMap<E, T> associate(Collection<E> master, Collection<T> target, BiPredicate<E, T> predicate) 关联 将集合target按条件与集合master配对static <E,T> KeyValuePairs<E, T> associateOne(Collection<E> master, Collection<T> target, BiPredicate<E, T> predicate) 关联 (明确是单个的) 将集合target按条件与集合master配对static <E> booleancontains(Collection<E> collection, Object target) 检查元素存在static <E> booleancontains(Collection<E> collection, Object target, Function<E, ?> function) 检查元素存在static <E> Set<E>difference(Collection<E> master, Collection<E> other) 差集static <E> Optional<E>获得元素static <E> List<E>getAllMatch(Collection<E> collection, Object target, Function<E, ?> function) 获得全部匹配的元素static <E> Optional<E>getFirstFalse(Collection<E> collection, Predicate<E> predicate) 获得第一个判断是false的元素static <E> Optional<E>getFirstMatch(Collection<E> collection, Object target) 获得第一个匹配的元素static <E> Optional<E>getFirstMatch(Collection<E> collection, Object target, Function<E, ?> function) 获得第一个匹配的元素static <E> Optional<E>getFirstTrue(Collection<E> collection, Predicate<E> predicate) 获得第一个判断是true的元素static <E,K, V> ListInMap<K, V> grouping(Collection<E> collection, Function<E, K> keySupplier, Function<E, V> valueSupplier) 分组static <K,V> ListInMap<K, V> grouping(Collection<V> collection, Function<V, K> keySupplier) static <E,K> Counter<K> groupingCount(Collection<E> collection, Function<E, K> keySupplier) 分组求数量static <E,K, V> Map<K, V> groupingUniqueKey(Collection<E> collection, Function<E, K> keySupplier, Function<E, V> valueSupplier) static <K,V> Map<K, V> groupingUniqueKey(Collection<V> collection, Function<V, K> keySupplier) static <E> Set<E>intersection(Collection<E> master, Collection<E>... other) 交集static <T extends Collection<E>,E>
Tmerge(Supplier<T> supplier, Collection<E>... collections) 合并多集合static <T> voidpagingProcess(int total, int size, BiConsumer<Integer, Integer> consumer) 分页处理 (通过总数)static <T,R> R pagingProcess(int total, int size, R initialValue, BiFunction<R, R, R> reduceFunction, BiFunction<Integer, Integer, R> function) 分页处理 (通过总数 含返回值)static <T> voidpagingProcess(List<T> list, int size, CollectionAdvice.PagingProcessor<T> processor) 分页处理static <T,R> R pagingProcess(List<T> list, int size, R initialValue, BiFunction<R, R, R> reduceFunction, CollectionAdvice.PagingReduceProcessor<T, R> processor) 分页处理 (含返回值)partition(Collection<E> collection, Predicate<E> predicate) 划分 按条件把集合拆分成满足条件和不满足条件的两个集合static <T,S> List<T> sort(Collection<T> master, Collection<S> sortTarget, BiPredicate<T, S> predicate) 指定排序 把master的元素值按sortTarget的元素值排序,条件按predicatestatic <T,S> List<T> sort(Collection<T> master, S[] sortTarget, BiPredicate<T, S> predicate) static <E> Set<E>union(Collection<E>... collections) 并集压缩 将两个集合的元素按索引捆绑到一起
-
Constructor Details
-
CollectionAdvice
public CollectionAdvice()
-
-
Method Details
-
get
获得元素 -
contains
检查元素存在 -
contains
检查元素存在 -
getFirstMatch
public static <E> Optional<E> getFirstMatch(Collection<E> collection, Object target, Function<E, ?> function) 获得第一个匹配的元素 -
getFirstMatch
获得第一个匹配的元素 -
getFirstTrue
获得第一个判断是true的元素 -
getFirstFalse
获得第一个判断是false的元素 -
getAllMatch
public static <E> List<E> getAllMatch(Collection<E> collection, Object target, Function<E, ?> function) 获得全部匹配的元素 -
allMatch
全部匹配 -
anyMatch
任意一个匹配 -
allAccept
判断所有元素的处理值相等 -
grouping
public static <E,K, ListInMap<K,V> V> grouping(Collection<E> collection, Function<E, K> keySupplier, Function<E, V> valueSupplier) 分组 -
grouping
-
groupingUniqueKey
public static <K,V> Map<K,V> groupingUniqueKey(Collection<V> collection, Function<V, K> keySupplier) -
groupingUniqueKey
public static <E,K, Map<K,V> V> groupingUniqueKey(Collection<E> collection, Function<E, K> keySupplier, Function<E, V> valueSupplier) -
groupingCount
分组求数量 -
union
并集 -
intersection
交集 -
difference
差集 -
merge
@SafeVarargs public static <T extends Collection<E>,E> T merge(Supplier<T> supplier, Collection<E>... collections) 合并多集合 -
associate
public static <E,T> ListInMap<E,T> associate(Collection<E> master, Collection<T> target, BiPredicate<E, T> predicate) 关联 将集合target按条件与集合master配对 -
associateOne
public static <E,T> KeyValuePairs<E,T> associateOne(Collection<E> master, Collection<T> target, BiPredicate<E, T> predicate) 关联 (明确是单个的) 将集合target按条件与集合master配对 -
partition
public static <E> TwoValues<List<E>,List<E>> partition(Collection<E> collection, Predicate<E> predicate) 划分 按条件把集合拆分成满足条件和不满足条件的两个集合 -
zip
压缩 将两个集合的元素按索引捆绑到一起 -
pagingProcess
public static <T> void pagingProcess(List<T> list, int size, CollectionAdvice.PagingProcessor<T> processor) 分页处理 -
pagingProcess
分页处理 (通过总数) -
pagingProcess
public static <T,R> R pagingProcess(List<T> list, int size, R initialValue, BiFunction<R, R, R> reduceFunction, CollectionAdvice.PagingReduceProcessor<T, R> processor) 分页处理 (含返回值) -
pagingProcess
public static <T,R> R pagingProcess(int total, int size, R initialValue, BiFunction<R, R, R> reduceFunction, BiFunction<Integer, Integer, R> function) 分页处理 (通过总数 含返回值) -
sort
public static <T,S> List<T> sort(Collection<T> master, Collection<S> sortTarget, BiPredicate<T, S> predicate) 指定排序 把master的元素值按sortTarget的元素值排序,条件按predicate -
sort
-