public abstract class CollectionsOpt extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
CollectionsOpt.ParentChild<T>
判断两个对象是否是父子关系,用于针对树形展示的数据结构进行排序
|
| 构造器和说明 |
|---|
CollectionsOpt() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> List<T> |
arrayToList(T[] arrayObj) |
static List<Object> |
breadthFirstTraverseForest(Collection<?> treeObjects,
String childrenPropertyName)
广度优先遍森林
|
static List<Object> |
breadthFirstTraverseTree(Object rootObject,
String childrenPropertyName)
广度优先遍树
|
static <T> void |
changeListItem(List<T> list,
int p1,
int p2)
交换List中两个对象的位置
|
static <T> T[] |
cloneArray(T[] souList) |
static <K,V> HashMap<K,V> |
cloneHashMap(Map<K,V> souMap) |
static <T> List<T> |
cloneList(Collection<T> souList)
克隆 一个 list
|
static <T> HashSet<T> |
cloneSet(Collection<T> souCollection) |
static <T> org.apache.commons.lang3.tuple.Triple<List<T>,List<org.apache.commons.lang3.tuple.Pair<T,T>>,List<T>> |
compareTwoList(List<T> oldList,
List<T> newList,
Comparator<T> compare)
对比两个列表,判断哪些需要新增、哪些需要删除、哪些需要更新
|
static <K,V> Map<K,V> |
copyMapWithoutNullItem(Map<K,V> map) |
static <T> Map<String,T> |
createHashMap(List<T> listData,
Function<T,String> func) |
static Map<String,Object> |
createHashMap(Object... objs)
参数必须是 string object string object ....
|
static <T> Map<String,T> |
createHashMap(String[] keys,
T[] values) |
static <T> HashSet<T> |
createHashSet(T... objs) |
static <T> List<T> |
createList(T... objs) |
static List<Object> |
depthFirstTraverseForest(Collection<?> treeObjects,
String childrenPropertyName)
深度优先遍森林
|
static void |
depthFirstTraverseTree(Object rootObject,
List<Object> expendTree,
String childrenPropertyName)
深度优先遍历树
|
static List<Object> |
depthFirstTraverseTree(Object rootObject,
String childrenPropertyName)
深度优先遍树
|
static <T,U> List<U> |
extraListProperties(List<T> list,
Function<T,U> propExtractor)
这个按道理可以同 stream来处理, 但是类型转换不太好弄
获取一个list中的所有对象的一个属性,并组成一个新的数组
|
static <T> T |
fetchFirstItem(Collection<T> collection) |
static <T> T |
fetchFirstItem(T[] array) |
static <T> TreeNode<T> |
fetchTreeBranch(List<T> list,
Predicate<T> startKey,
CollectionsOpt.ParentChild<? super T> c,
int levels) |
static <T> T[] |
listToArray(Collection<T> listObj)
将list(Collection 所以 set也可以) 转换为数组, list.toArray(T[]) 感觉不太好用,要new一个接受的数组对象
|
static <T> T[] |
listToArray(Collection<T> listObj,
Class<T> classType)
将list(Collection 所以 set也可以) 转换为数组, list.toArray(T[]) 感觉不太好用,要new一个接受的数组对象
|
static <T> List<Integer> |
makeJqueryTreeIndex(List<T> list,
CollectionsOpt.ParentChild<? super T> c)
对排序好的树形数组结构 找到JQueryTree要的Indexes
|
static <T,R> List<R> |
mapArrayToList(T[] array,
Function<T,R> func) |
static <T,R> Set<R> |
mapArrayToSet(T[] array,
Function<T,R> func) |
static <T,R> List<R> |
mapCollectionToList(Collection<T> array,
Function<T,R> func) |
static <T,R> List<R> |
mapCollectionToList(Collection<T> array,
Function<T,R> func,
boolean ignoreNull) |
static <D,K,V> Map<K,V> |
mapCollectionToMap(Collection<D> array,
Function<D,K> keyFunc,
Function<D,V> valueFunc) |
static <T,R> Set<R> |
mapCollectionToSet(Collection<T> array,
Function<T,R> func) |
static <T,U> CollectionsOpt.ParentChild<? super T> |
mapParentANdChild(Function<? super T,? extends U> pkExtractor,
Function<? super T,? extends U> parentPkExtractor) |
static <T> List<T> |
mergeTwoList(List<T> list1,
List<T> list2)
合并两个数组,注意不是连接,相同位置的以list1 为主
|
static <T> void |
moveListItem(List<T> list,
int item,
int pos)
移动List一个对象到新的位置
|
static Map<String,String> |
objectMapToStringMap(Map<?,?> objectMap) |
static List<Object> |
objectToList(Object object) |
static Map<String,Object> |
objectToMap(Object object) |
static List<String> |
removeBlankString(List<String> list)
移除String List中的所有 Blank 对象
|
static String[] |
removeBlankString(String[] list)
移除List中的所有null对象
|
static <T> List<T> |
removeNullItem(List<T> list)
移除List中的所有null对象
|
static <T> T[] |
removeNullItem(T[] list)
移除List中的所有null对象
|
static <T> void |
sortAsTree(List<T> list,
CollectionsOpt.ParentChild<? super T> c)
将数组结构按照树形展示的形式进行排序,将所有孩子元素放到父元素的下面
深度优先的排序
|
static <T,U> void |
sortAsTree(List<T> list,
Function<? super T,? extends U> pkExtractor,
Function<? super T,? extends U> parentPkExtractor)
将数组结构按照树形展示的形式进行排序,将所有孩子元素放到父元素的下面
深度优先的排序
|
static <T> com.alibaba.fastjson2.JSONArray |
sortAsTreeAndToJSON(List<T> treeList,
CollectionsOpt.ParentChild<? super T> c,
String childrenPropertyName)
将列表转换为tree结构的json
|
static <T> com.alibaba.fastjson2.JSONArray |
sortAsTreeAndToJSON2(List<T> treeList,
CollectionsOpt.ParentChild<? super T> c,
String childrenPropertyName)
将列表转换为tree结构的json
和 sortAsTreeAndToJSON2 用不同的算法实现,这个需要额外的空间,用递归实现。
|
static <T> List<TreeNode<T>> |
storedAsTree(List<T> list,
CollectionsOpt.ParentChild<? super T> c)
将数组结构按照树形展示的形式进行排序,将所有孩子元素放到父元素的下面
深度优先的排序
|
static <K,V> Map<K,V> |
translateMapType(Map<?,?> objectMap,
Function<Object,K> transKey,
Function<Object,V> transValue) |
static <T> com.alibaba.fastjson2.JSONArray |
treeToJSONArray(List<T> treeList,
CollectionsOpt.ParentChild<? super T> c,
String childrenPropertyName)
将TreeList转换为JSONArray
|
static <T> com.alibaba.fastjson2.JSONArray |
treeToJSONArray(List<TreeNode<T>> treeList,
String childrenPropertyName)
将TreeList转换为JSONArray
|
static <K,V> Map<K,V> |
unionTwoMap(Map<K,V> map1,
Map<K,V> map2)
合并两个 map 有相同key的元素,以map1为准
|
static <T> T |
unmodifiableObject(T obj) |
public static <T> void moveListItem(List<T> list, int item, int pos)
T - 泛型类型list - 输入列表item - 位置1pos - 位置2public static <T> void changeListItem(List<T> list, int p1, int p2)
T - 泛型类型list - 输入列表p1 - 位置1p2 - 位置2public static <T,U> CollectionsOpt.ParentChild<? super T> mapParentANdChild(Function<? super T,? extends U> pkExtractor, Function<? super T,? extends U> parentPkExtractor)
public static <T> void sortAsTree(List<T> list, CollectionsOpt.ParentChild<? super T> c)
T - 泛型类型list - 输入列表c - 对比接口public static <T,U> void sortAsTree(List<T> list, Function<? super T,? extends U> pkExtractor, Function<? super T,? extends U> parentPkExtractor)
T - 泛型类型U - 主键类型list - 输入列表pkExtractor - 父对象 获取 自己的主键parentPkExtractor - 子对象 获取 父对象主键public static <T> List<Integer> makeJqueryTreeIndex(List<T> list, CollectionsOpt.ParentChild<? super T> c)
T - 泛型类型list - 输入列表c - 对比接口public static <T> List<T> removeNullItem(List<T> list)
T - 泛型类型list - 输入列表public static <T> T[] removeNullItem(T[] list)
T - 泛型类型list - 输入数组public static List<String> removeBlankString(List<String> list)
list - 输入字符串列表public static String[] removeBlankString(String[] list)
list - 输入字符串数组public static <T> com.alibaba.fastjson2.JSONArray treeToJSONArray(List<T> treeList, CollectionsOpt.ParentChild<? super T> c, String childrenPropertyName)
T - 泛型类型treeList - 必须是已经通过 sortAsTree 排序好的listc - 比较算法,需要实现接口 CollectionsOpt.ParentChild TchildrenPropertyName - 为孩子的 属性名public static <T> com.alibaba.fastjson2.JSONArray sortAsTreeAndToJSON(List<T> treeList, CollectionsOpt.ParentChild<? super T> c, String childrenPropertyName)
T - 泛型类型treeList - 待排序的Listc - 比较算法,需要实现接口 CollectionsOpt.ParentChild TchildrenPropertyName - 为孩子的 属性名public static <T> List<TreeNode<T>> storedAsTree(List<T> list, CollectionsOpt.ParentChild<? super T> c)
T - 泛型类型list - 输入数组c - 对比接口public static <T> TreeNode<T> fetchTreeBranch(List<T> list, Predicate<T> startKey, CollectionsOpt.ParentChild<? super T> c, int levels)
public static <T> com.alibaba.fastjson2.JSONArray treeToJSONArray(List<TreeNode<T>> treeList, String childrenPropertyName)
T - 泛型类型treeList - 需要排序的对象列表 必须是 ListchildrenPropertyName - 为孩子的 属性名public static <T> com.alibaba.fastjson2.JSONArray sortAsTreeAndToJSON2(List<T> treeList, CollectionsOpt.ParentChild<? super T> c, String childrenPropertyName)
T - 泛型类型treeList - 待排序的Listc - 比较算法,需要实现接口 CollectionsOpt.ParentChild TchildrenPropertyName - 为孩子的 属性名public static void depthFirstTraverseTree(Object rootObject, List<Object> expendTree, String childrenPropertyName)
rootObject - 根节点expendTree - 展开的列表childrenPropertyName - 孩子节点public static List<Object> depthFirstTraverseForest(Collection<?> treeObjects, String childrenPropertyName)
treeObjects - 森林listchildrenPropertyName - 孩子节点public static List<Object> depthFirstTraverseTree(Object rootObject, String childrenPropertyName)
rootObject - 树的根对象childrenPropertyName - 孩子节点public static List<Object> breadthFirstTraverseForest(Collection<?> treeObjects, String childrenPropertyName)
treeObjects - 森林listchildrenPropertyName - 孩子节点public static List<Object> breadthFirstTraverseTree(Object rootObject, String childrenPropertyName)
rootObject - 树的根节点childrenPropertyName - 孩子节点public static <T> List<T> cloneList(Collection<T> souList)
T - 模版类型souList - 源列表public static <T> T[] cloneArray(T[] souList)
public static <T> org.apache.commons.lang3.tuple.Triple<List<T>,List<org.apache.commons.lang3.tuple.Pair<T,T>>,List<T>> compareTwoList(List<T> oldList, List<T> newList, Comparator<T> compare)
T - 泛型类型oldList - 原始listnewList - 新的listcompare - 为对象T的主键排序对比函数,public static <T> T[] listToArray(Collection<T> listObj, Class<T> classType)
T - 类型listObj - Collection 对象 可以是list 也可以是 setclassType - T 的类型public static <T> T[] listToArray(Collection<T> listObj)
T - 类型listObj - Collection 对象 可以是list 也可以是 setpublic static <T> List<T> arrayToList(T[] arrayObj)
public static Map<String,Object> createHashMap(Object... objs)
objs - 参数必须是 string object string object ....public static <T> Map<String,T> createHashMap(List<T> listData, Function<T,String> func)
public static <K,V> Map<K,V> unionTwoMap(Map<K,V> map1, Map<K,V> map2)
K - key类型V - value类型map1 - 主mapmap2 - 辅mappublic static <T> List<T> mergeTwoList(List<T> list1, List<T> list2)
T - 数组元素类型list1 - 主数据list2 - 辅数组@SafeVarargs public static <T> List<T> createList(T... objs)
T - 参数类型objs - 参数类型需要一致public static <T,U> List<U> extraListProperties(List<T> list, Function<T,U> propExtractor)
T - 数组类型U - 属性类型list - 数组propExtractor - 对象方法public static <T> HashSet<T> cloneSet(Collection<T> souCollection)
@SafeVarargs public static <T> HashSet<T> createHashSet(T... objs)
T - 参数类型objs - 参数类型需要一致public static <T> T unmodifiableObject(T obj)
public static Map<String,Object> objectToMap(Object object)
object - map的key必须是string类型否则会报错public static <K,V> Map<K,V> translateMapType(Map<?,?> objectMap, Function<Object,K> transKey, Function<Object,V> transValue)
public static <T> T fetchFirstItem(Collection<T> collection)
public static <T> T fetchFirstItem(T[] array)
public static <T,R> Set<R> mapCollectionToSet(Collection<T> array, Function<T,R> func)
public static <T,R> List<R> mapCollectionToList(Collection<T> array, Function<T,R> func, boolean ignoreNull)
public static <T,R> List<R> mapCollectionToList(Collection<T> array, Function<T,R> func)
public static <D,K,V> Map<K,V> mapCollectionToMap(Collection<D> array, Function<D,K> keyFunc, Function<D,V> valueFunc)
Copyright © 2025 江苏南大先腾信息产业股份有限公司. All rights reserved.