CollectionKitpublic class CollectorUtils extends Object
| 构造器 | 说明 |
|---|---|
CollectorUtils() |
已过时。
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static <E> List<List<E>> |
balance(int partitions,
E[]... arrays) |
已过时。
将多个数组中的元素尽可能均匀分配在指定数量(partitions)的
List 中。 |
static <E> List<List<E>> |
balance(int partitions,
Collection<? extends Collection<E>> collections) |
已过时。
将多个
List 中的元素尽可能均匀分配在指定数量(partitions)的 List 中。 |
static <E> List<List<E>> |
balance(int partitions,
Collection<E>... listArray) |
已过时。
将多个
List 中的元素尽可能均匀分配在指定数量(partitions)的 List 中。 |
static <T> List<List<T>> |
divide(List<T> list,
int perBatchSize) |
已过时。
Divide list to multi lists by per batch size.
|
static <K,V> List<Map<K,V>> |
divide(Map<K,V> map,
int perBatchSize) |
已过时。
Divide map to multi maps by per batch size.
|
static <T> List<Set<T>> |
divide(Set<T> set,
int perBatchSize) |
已过时。
Divide set to multi sets by per batch size.
|
static <T> List<T[]> |
divide(T[] arr,
int perBatchSize) |
已过时。
Divide array to multi arrays by per batch size.
|
private static <E> void |
fastSortForBalance(List<Map.Entry<Integer,List<E>>> sortedEntries) |
已过时。
|
static <T> T |
findNth(Collection<T> ts,
Predicate<? super T> filter,
int nth) |
已过时。
从过滤后的集合中获取第n个元素,超出元素范围,则返回
null |
static <T> com.iofairy.tuple.Tuple2<T,Integer> |
findNth(List<T> ts,
Predicate<? super T> filter,
int nth) |
已过时。
从过滤后的列表中获取第n个元素及在原列表中的序号,超出元素范围,则返回
null |
static <T> com.iofairy.tuple.Tuple2<T,Integer> |
findNth(T[] ts,
Predicate<? super T> filter,
int nth) |
已过时。
从获取过滤后的数组中获取第n个元素及在原数组中的序号,超出元素范围,则返回
null |
static <T> T |
findRandom(Collection<T> ts,
Predicate<? super T> filter) |
已过时。
从过滤后的集合中随机获取元素
|
static <T> com.iofairy.tuple.Tuple2<T,Integer> |
findRandom(List<T> ts,
Predicate<? super T> filter) |
已过时。
从过滤后的列表中随机获取元素及在原列表中的序号
|
static <T> com.iofairy.tuple.Tuple2<T,Integer> |
findRandom(T[] ts,
Predicate<? super T> filter) |
已过时。
从过滤后的数组中随机获取元素及在原数组中的序号
|
public static <T> List<T[]> divide(T[] arr, int perBatchSize)
Integer[] intArr = {0, 1, 2, 3, 4, 5, 6, 7};
List<Integer[]> divided = divide(intArr, 3);
divided result:
[[0, 1, 2], [3, 4, 5], [6, 7]]
T - type of arrayarr - arrayperBatchSize - per batch sizepublic static <T> List<List<T>> divide(List<T> list, int perBatchSize)
List<String> strList = Arrays.asList("a", "b", "c", "d", "e");
List<List<String>> divided = divide(strList, 2);
divided result:
[[a, b], [c, d], [e]]
T - type of listlist - listperBatchSize - per batch sizepublic static <T> List<Set<T>> divide(Set<T> set, int perBatchSize)
Set<Integer> intSet = new HashSet<>(); intSet.add(1); intSet.add(2); intSet.add(3); List<Set<Integer>> divided = divide(intSet, 2);divided result:
[[1, 2], [3]]
T - type of setset - setperBatchSize - per batch sizepublic static <K,V> List<Map<K,V>> divide(Map<K,V> map, int perBatchSize)
Map<String, Integer> map = new HashMap<>();
map.put("a", 1);
map.put("b", 2);
map.put("c", 3);
List<Map<String, Integer>> divided = divide(map, 2);
divided result:
[{a=1, b=2}, {c=3}]
K - type of keyV - type of valuemap - mapperBatchSize - per batch sizepublic static <E> List<List<E>> balance(int partitions, Collection<? extends Collection<E>> collections)
List 中的元素尽可能均匀分配在指定数量(partitions)的 List 中。
但原来在同一个 List 中的元素,分配以后,依然在同一个 List 中。
Examples:
List<Integer> list0 = Arrays.asList(11, 12, 13, 14, 15); List<Integer> list1 = Arrays.asList(26); List<Integer> list2 = Arrays.asList(57, 58, 59); List<Integer> list3 = Arrays.asList(30, 31); List<Integer> list4 = Arrays.asList(83, 84, 85); List<Integer> list5 = Arrays.asList(71, 72); List<List<Integer>> lists = Arrays.asList(list0, list1, list2, list3, list4, list5); List<List<Integer>> balance1 = CollectorUtils.balance(3, lists); //-- balance1: [[57, 58, 59, 30, 31], [11, 12, 13, 14, 15], [83, 84, 85, 71, 72, 26]] List<List<Integer>> balance2 = CollectorUtils.balance(4, lists); //-- balance2: [[83, 84, 85], [57, 58, 59, 26], [30, 31, 71, 72], [11, 12, 13, 14, 15]]
E - 元素类型partitions - 分配后 List 的数量collections - 待分配的 List 列表List 列表@SafeVarargs public static <E> List<List<E>> balance(int partitions, Collection<E>... listArray)
List 中的元素尽可能均匀分配在指定数量(partitions)的 List 中。
但原来在同一个 List 中的元素,分配以后,依然在同一个 List 中。E - 元素类型partitions - 分配后 List 的数量listArray - 待分配的 List 数组List 列表balance(int, Collection)@SafeVarargs public static <E> List<List<E>> balance(int partitions, E[]... arrays)
List 中。
但原来在同一个数组中的元素,分配以后,会在同一个 List 中。E - 元素类型partitions - 分配后 List 的数量arrays - 待分配的数组List 列表balance(int, Collection)private static <E> void fastSortForBalance(List<Map.Entry<Integer,List<E>>> sortedEntries)
E - elements type in ListsortedEntries - sortedEntriesbalance(int, Collection)public static <T> T findNth(Collection<T> ts, Predicate<? super T> filter, int nth)
nullT - 集合元素类型ts - 集合filter - 对集合过滤,为 null 时,不过滤nth - 第n个元素,从 0 开始, 负数 则从最后一个元素开始往前面索引,-1 代表最后一个元素public static <T> com.iofairy.tuple.Tuple2<T,Integer> findNth(List<T> ts, Predicate<? super T> filter, int nth)
nullT - 列表元素类型ts - 列表filter - 对列表过滤,为 null 时,不过滤nth - 第n个元素,从 0 开始,负数 则从最后一个元素开始往前面索引,-1 代表最后一个元素public static <T> com.iofairy.tuple.Tuple2<T,Integer> findNth(T[] ts, Predicate<? super T> filter, int nth)
nullT - 数组元素类型ts - 数组filter - 对数组过滤,为 null 时,不过滤nth - 第n个元素,从 0 开始,负数 则从最后一个元素开始往前面索引,-1 代表最后一个元素public static <T> T findRandom(Collection<T> ts, Predicate<? super T> filter)
T - 集合元素类型ts - 集合filter - 对集合过滤,为 null 时,不过滤public static <T> com.iofairy.tuple.Tuple2<T,Integer> findRandom(List<T> ts, Predicate<? super T> filter)
T - 列表元素类型ts - 列表filter - 对列表过滤,为 null 时,不过滤Copyright © 2023. All rights reserved.