public final class Collects extends Object
| 构造器和说明 |
|---|
Collects() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <A,B,T> List<List<T>> |
cartesian(List<A> x,
List<B> y,
BiFunction<A,B,T> fun)
Compute cartesian product
[1, 2, 3] x [4, 5, 6] = [[4, 5, 6], [8, 10, 12], [12, 15, 18]]
|
static <T> T[] |
concat(IntFunction<T[]> generator,
T[]... arrays)
Returns a new array for merged the generic array generator
|
static <T> List<T> |
concat(List<T> list,
T... array) |
static <E,R> List<R> |
convert(Collection<E> collection,
Function<E,R> mapper) |
static <E,R> List<R> |
convert(Collection<E> collection,
Predicate<? super E> predicate,
Function<E,R> mapper) |
static <T> List<T> |
different(List<T> list1,
List<T> list2)
list差集
different([1,2,3], [2,3,4]) = [1,4]
|
static <K,V> Map<K,V> |
different(Map<K,V> map1,
Map<K,V> map2)
map差集
|
static <T> Set<T> |
different(Set<T> set1,
Set<T> set2)
The two set different elements
|
static <T> List<T> |
duplicate(Collection<T> list) |
static <T,R> List<R> |
duplicate(Collection<T> list,
Function<T,R> mapper)
Returns the duplicates elements for list
|
static <T> void |
expand(List<T> list,
int size,
Supplier<T> supplier)
Expand the list size
|
static <T> T |
get(List<T> list,
int index) |
static <T> T |
get(T[] array,
int index) |
static <T> T |
getFirst(Collection<T> values)
Gets the first element for values
|
static <T> T |
getLast(Collection<T> values)
Gets the last element for values
|
static <T> List<T> |
intersect(Collection<T> coll1,
Collection<T> coll2)
two Collection intersect
intersect([1,2,3], [2,3,4]) = [2,3]
|
static <T> T[] |
intersect(T[] array1,
T[] array2)
two array intersect
|
static <T> T[] |
newArray(Class<? extends T[]> newType,
int length) |
static <E> LinkedList<E> |
newLinkedList(E element) |
static List<int[]> |
partition(int[] array,
int size)
Returns consecutive sub array of an array,
each of the same size (the final list may be smaller).
|
static <T> List<T> |
requireNonEmpty(List<T> list)
Checks that the specified list reference is not null and not empty,
throws a customized
IllegalStateException if it is. |
static <T> T[] |
requireNonEmpty(T[] array)
Checks that the specified array reference is not null and not empty,
throws a customized
IllegalStateException if it is. |
static List<Object[]> |
rotate(List<Object[]> list)
Rotate list array data
[[a,b,c,d],[1,2,3,4]] -> [[a,1],[b,2],[c,3],[d,4]]
|
static <T> void |
set(List<T> list,
int index,
T obj)
Puts the element to list specified index
|
static int[] |
sortAndGetIndexSwapMapping(int[] array) |
static <E> Stream<E> |
stream(Collection<E> collection) |
static <T> T[] |
toArray(T... args)
转数组
|
static List<Object> |
toList(Object obj)
object to list
|
static <T> List<T> |
union(Collection<T> coll1,
Collection<T> coll2)
two Collection union result
|
public static <T> T[] toArray(T... args)
args - public static List<Object> toList(Object obj)
obj - of elementspublic static <E> LinkedList<E> newLinkedList(E element)
public static <T> T getFirst(Collection<T> values)
T - the values element typevalues - the valuespublic static <T> T getLast(Collection<T> values)
T - the values element typevalues - the valuespublic static <T> T get(T[] array,
int index)
public static <T> T get(List<T> list, int index)
public static <T> List<T> intersect(Collection<T> coll1, Collection<T> coll2)
coll1 - the collection 1coll2 - the collection 2public static <T> T[] intersect(T[] array1,
T[] array2)
array1 - array2 - public static <T> List<T> union(Collection<T> coll1, Collection<T> coll2)
coll1 - coll2 - public static <T> List<T> different(List<T> list1, List<T> list2)
list1 - list2 - public static <T> Set<T> different(Set<T> set1, Set<T> set2)
set1 - set2 - public static <K,V> Map<K,V> different(Map<K,V> map1, Map<K,V> map2)
map1 - map2 - public static <T> List<T> duplicate(Collection<T> list)
public static <T,R> List<R> duplicate(Collection<T> list, Function<T,R> mapper)
list - the listpublic static <T> T[] concat(IntFunction<T[]> generator, T[]... arrays)
generator - the generic array generatorarrays - the multiple generic object arrayorg.apache.commons.lang3.ArrayUtils#addAll(T[] array1, T... array2)public static <T> void set(List<T> list, int index, T obj)
list - a listindex - spec indexobj - the elementpublic static <T> void expand(List<T> list, int size, Supplier<T> supplier)
T - the element typelist - the listsize - the target sizesupplier - element providerpublic static List<int[]> partition(int[] array, int size)
Collects.partition(new int[]{1,1,2,5,3}, 1) -> [1, 1, 2, 5, 3]
Collects.partition(new int[]{1,1,2,5,3}, 3) -> [1, 1]; [2, 5]; [3]
Collects.partition(new int[]{1,1,2,5,3}, 5) -> [1]; [1]; [2]; [5]; [3]
Collects.partition(new int[]{1,1,2,5,3}, 6) -> [1]; [1]; [2]; [5]; [3]
Collects.partition(new int[]{1,1,2,5,3}, 100) -> [1]; [1]; [2]; [5]; [3]
array - the arraysize - the sizepublic static <A,B,T> List<List<T>> cartesian(List<A> x, List<B> y, BiFunction<A,B,T> fun)
x - the list of type Ay - the list of type Bfun - convert A and B to Tpublic static List<Object[]> rotate(List<Object[]> list)
list - the listpublic static int[] sortAndGetIndexSwapMapping(int[] array)
public static <T> T[] requireNonEmpty(T[] array)
IllegalStateException if it is.T - the type of the array elementarray - the arrayarray if not null and not emptypublic static <T> List<T> requireNonEmpty(List<T> list)
IllegalStateException if it is.T - the type of the list elementlist - the listlist if not null and not emptypublic static <E,R> List<R> convert(Collection<E> collection, Function<E,R> mapper)
public static <E,R> List<R> convert(Collection<E> collection, Predicate<? super E> predicate, Function<E,R> mapper)
@SafeVarargs public static <T> List<T> concat(List<T> list, T... array)
public static <T> T[] newArray(Class<? extends T[]> newType, int length)
public static <E> Stream<E> stream(Collection<E> collection)
Copyright © 2023. All rights reserved.