Class CollKit

java.lang.Object
org.aoju.bus.core.toolkit.CollKit

public class CollKit extends Object
集合相关工具类
Since:
Java 17+
Author:
Kimi Liu
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    针对一个参数做相应的操作
    static interface 
    Hash计算接口
    static interface 
    针对两个参数做相应的操作,例如Map中的KEY和VALUE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Collection<T>
    addAll(Collection<T> collection, Iterable<T> iterable)
    加入全部
    static <T> Collection<T>
    addAll(Collection<T> collection, Object value)
    将指定对象全部加入到集合中 提供的对象如果为集合类型,会自动转换为目标元素类型
    static <T> Collection<T>
    addAll(Collection<T> collection, Object value, Type elementType)
    将指定对象全部加入到集合中 提供的对象如果为集合类型,会自动转换为目标元素类型
    static <T> Collection<T>
    addAll(Collection<T> collection, Enumeration<T> enumeration)
    加入全部
    static <T> Collection<T>
    addAll(Collection<T> collection, Iterator<T> iterator)
    加入全部
    static <T> Collection<T>
    addAll(Collection<T> collection, T[] values)
    加入全部
    static List<String>
    addAll(List<String> list, String part, boolean isTrim, boolean ignoreEmpty)
    将字符串加入List中
    static <T> List<T>
    addAllIfNotContains(List<T> list, List<T> otherList)
    将另一个列表中的元素加入到列表中,如果列表中已经存在此元素则忽略之
    static <E> Enumeration<E>
    Iterator转换为Enumeration
    static <E> Iterable<E>
    static <E> Iterator<E>
    Enumeration转换为Iterator
    static void
    clear(Collection<?>... collections)
    清除一个或多个集合内的元素,每个集合调用clear()方法
    static <T> T[]
    concat(T[] one, T[] other, Class<T> clazz)
    Concatenates 2 arrays
    static boolean
    contains(Collection<?> collection, Object value)
    判断指定集合是否包含指定值,如果集合为空(null或者空),返回false,否则找到元素返回true
    static <T> boolean
    contains(Collection<T> collection, Predicate<? super T> containFunc)
    自定义函数判断集合是否包含某类值
    static boolean
    contains(Enumeration<?> enumeration, Object element)
    检查给定枚举是否包含给定元素.
    static boolean
    contains(Iterator<?> iterator, Object element)
    检查给定的迭代器是否包含给定的元素.
    static <T> boolean
    contains(T[] array, T element)
    检查给定数组是否包含给定元素
    static boolean
    containsAll(Collection<?> coll1, Collection<?> coll2)
    集合1中是否包含集合2中所有的元素,即集合2是否为集合1的子集
    static boolean
    containsAny(Collection<?> coll1, Collection<?> coll2)
    其中一个集合在另一个集合中是否至少包含一个元素,既是两个集合是否至少有一个共同的元素
    static <T> int
    count(Iterable<T> iterable, Matcher<T> matcher)
    集合中匹配规则的数量
    static <T> Map<T,Integer>
    countMap(Iterable<T> collection)
    根据集合返回一个元素计数的 Map 所谓元素计数就是假如这个集合中某个元素出现了n次,那将这个元素做为key,n做为value 例如:[a,b,c,c,c] 得到: a: 1 b: 1 c: 3
    static <T> Collection<T>
    create(Class<?> collectionType)
    创建新的集合对象
    static <K, V> Map<K,V>
    createMap(Class<?> mapType)
    创建Map 传入抽象MapAbstractMapMap类将默认创建HashMap
    static <T extends Collection<E>, E>
    T
    defaultIfEmpty(T collection, Supplier<? extends T> supplier)
    如果给定集合为空,返回默认集合
    static <T extends Collection<E>, E>
    T
    defaultIfEmpty(T collection, T defaultCollection)
    如果给定集合为空,返回默认集合
    static <T> Collection<T>
    disjunction(Collection<T> coll1, Collection<T> coll2)
    两个集合的差集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留两个集合中此元素个数差的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[c],此结果中只保留了一个 任意一个集合为空,返回另一个集合 两个集合无交集则返回两个集合的组合
    static <T> List<T>
    distinct(Collection<T> collection)
    去重集合
    static <T, K> List<T>
    distinct(Collection<T> collection, Function<T,K> uniqueGenerator, boolean override)
    根据函数生成的KEY去重集合,如根据Bean的某个或者某些字段完成去重 去重可选是保留最先加入的值还是后加入的值
    static <T> Predicate<T>
    distinct(Function<? super T,?> key)
    去重集合
    static <T> List<T>
    获取一个空List,这个空List不可变
    static <T> List<T>
    emptyIfNull(List<T> list)
    如果提供的集合为null,返回一个不可变的默认空集合,否则返回原集合 空集合使用Collections.emptyList()
    static <T> Set<T>
    emptyIfNull(Set<T> set)
    如果提供的集合为null,返回一个不可变的默认空集合,否则返回原集合 空集合使用Collections.emptySet()
    static List<Object>
    extract(Iterable<?> collection, Editor<Object> editor)
    通过Editor抽取集合元素中的某些值返回为新列表 例如提供的是一个Bean列表,通过Editor接口实现获取某个字段值,返回这个字段值组成的新列表
    static List<Object>
    extract(Iterable<?> collection, Editor<Object> editor, boolean ignoreNull)
    通过Editor抽取集合元素中的某些值返回为新列表 例如提供的是一个Bean列表,通过Editor接口实现获取某个字段值,返回这个字段值组成的新列表
    static <T> Collection<T>
    filter(Collection<T> collection, Editor<T> editor)
    过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
    static <E> Iterator<E>
    filter(Iterator<E> iter, Filter<E> filter)
    过滤集合,此方法在原集合上直接修改 通过实现Filter接口,完成元素的过滤,这个Filter实现可以实现以下功能:
    static <T> List<T>
    filter(List<T> list, Editor<T> editor)
    过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
    static <K, V> Map<K,V>
    filter(Map<K,V> map, Editor<Map.Entry<K,V>> editor)
    过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
    static <K, V> Map<K,V>
    filter(Map<K,V> map, Filter<Map.Entry<K,V>> filter)
    过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
    static <T extends Iterable<E>, E>
    T
    filter(T iter, Filter<E> filter)
    过滤集合,此方法在原集合上直接修改 通过实现Filter接口,完成元素的过滤,这个Filter实现可以实现以下功能:
    static <T> T
    findOne(Iterable<T> collection, Filter<T> filter)
    查找第一个匹配元素对象
    static <T> T
    findOneByField(Iterable<T> collection, String fieldName, Object fieldValue)
    查找第一个匹配元素对象 如果集合元素是Map,则比对键和值是否相同,相同则返回 如果为普通Bean,则通过反射比对元素字段名对应的字段值是否相同,相同则返回 如果给定字段值参数是null 且元素对象中的字段值也为null则认为相同
    static <T> Optional<T>
    找到第一个不为 null 的元素
    static Object
    forceGetFieldValue(Object object, String fieldName)
    获取指定对象的指定属性值(去除private,protected的限制)
    static <T> void
    forEach(Enumeration<T> enumeration, CollKit.Consumer<T> consumer)
    循环遍历 Enumeration,使用CollKit.Consumer 接受遍历的每条数据,并针对每条数据做处理
    static <T> void
    forEach(Iterator<T> iterator, CollKit.Consumer<T> consumer)
    循环遍历 Iterator,使用CollKit.Consumer 接受遍历的每条数据,并针对每条数据做处理
    static <K, V> void
    forEach(Map<K,V> map, CollKit.KVConsumer<K,V> kvConsumer)
    循环遍历Map,使用CollKit.KVConsumer 接受遍历的每条数据,并针对每条数据做处理
    static <T> T
    get(Collection<T> collection, int index)
    获取集合中指定下标的元素值,下标可以为负数,例如-1表示最后一个元素 如果元素越界,返回null
    static <T> List<T>
    getAny(Collection<T> collection, int... indexes)
    获取集合中指定多个下标的元素值,下标可以为负数,例如-1表示最后一个元素
    static List<Object>
    getFieldValues(Iterable<?> collection, String fieldName)
    获取给定Bean列表中指定字段名对应字段值的列表 列表元素支持Bean与Map
    static <T> T
    getFirst(Iterable<T> iterable)
    获取集合的第一个元素
    static <T> T
    getFirst(Iterator<T> iterator)
    获取集合的第一个元素
    static <T> T
    getLast(Collection<T> collection)
    获取集合的最后一个元素
    static <T> List<List<T>>
    group(Collection<T> collection, CollKit.Hash<T> hash)
    分组,按照CollKit.Hash接口定义的hash算法,集合中的元素放入hash值对应的子列表中
    static <E, T, U> Map<T,Map<U,E>>
    group2Map(Collection<E> collection, Function<E,T> key1, Function<E,U> key2)
    将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,E>>
    static <E, T, U> Map<T,Map<U,E>>
    group2Map(Collection<E> collection, Function<E,T> key1, Function<E,U> key2, boolean isParallel)
    将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,E>>
    static <E, K, U> Map<K,Map<U,List<E>>>
    groupBy2Key(Collection<E> collection, Function<E,K> key1, Function<E,U> key2)
    将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,List<E>>>
    static <E, K, U> Map<K,Map<U,List<E>>>
    groupBy2Key(Collection<E> collection, Function<E,K> key1, Function<E,U> key2, boolean isParallel)
    将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,List<E>>>
    static <T> List<List<T>>
    groupByField(Collection<T> collection, String fieldName)
    根据元素的指定字段名分组,非Bean都放在第一个分组中
    static <E, K> Map<K,List<E>>
    groupByKey(Collection<E> collection, Function<E,K> key)
    将collection按照规则(比如有相同的班级id)分类成map Collection<E> -------> Map<K,List<E>>
    static <E, K> Map<K,List<E>>
    groupByKey(Collection<E> collection, Function<E,K> key, boolean isParallel)
    将collection按照规则(比如有相同的班级id)分类成map Collection<E> -------> Map<K,List<E>>
    static <T, K> Collector<T,?,Map<K,List<T>>>
    groupingBy(Function<? super T,? extends K> classifier)
    提供对null值友好的groupingBy操作的Collector实现
    static <T, K, D, A, M extends Map<K, D>>
    Collector<T,?,M>
    groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
    提供对null值友好的groupingBy操作的Collector实现,可指定map类型
    static <T, K, A, D> Collector<T,?,Map<K,D>>
    groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
    提供对null值友好的groupingBy操作的Collector实现
    static <E, K, V> Map<K,List<V>>
    groupKeyValue(Collection<E> collection, Function<E,K> key, Function<E,V> value)
    将collection按照规则(比如有相同的班级id)分类成map,map中的key为班级id,value为班级名 Collection<E> -------> Map<K,List<V>>
    static <E, K, V> Map<K,List<V>>
    groupKeyValue(Collection<E> collection, Function<E,K> key, Function<E,V> value, boolean isParallel)
    将collection按照规则(比如有相同的班级id)分类成map,map中的key为班级id,value为班级名 Collection<E> -------> Map<K,List<V>>
    static boolean
    hasNull(Iterable<?> iterable)
    是否包含null元素
    static <T> int
    indexOf(Collection<T> collection, Matcher<T> matcher)
    获取匹配规则定义中匹配到元素的第一个位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
    static <T> int[]
    indexOfAll(Collection<T> collection, Matcher<T> matcher)
    获取匹配规则定义中匹配到元素的所有位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
    static <T> Collection<T>
    intersection(Collection<T> coll1, Collection<T> coll2)
    两个集合的交集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最少的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c],此结果中只保留了两个c
    static <T> Collection<T>
    intersection(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
    多个集合的交集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最少的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c],此结果中只保留了两个c
    static <T> Set<T>
    intersectOne(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
    多个集合的交集 针对一个集合中存在多个相同元素的情况,只保留一个 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c],此结果中只保留了一个c
    static boolean
    isEmpty(Iterable<?> iterable)
    Iterable是否为空
    static boolean
    isEmpty(Collection<?> collection)
    集合是否为空
    static boolean
    isEmpty(Enumeration<?> enumeration)
    Enumeration是否为空
    static boolean
    isEmpty(Iterator<?> Iterator)
    Iterator是否为空
    static boolean
    isEmpty(Map<?,?> map)
    Map是否为空
    static boolean
    isEqualList(Collection<?> list1, Collection<?> list2)
    判断两个Collection 是否元素和顺序相同,返回true的条件是: 两个Collection必须长度相同 两个Collection元素相同index的对象必须equals,满足Objects.equals(Object, Object) 此方法来自Apache-Commons-Collections4。
    static boolean
    isNotEmpty(Iterable<?> iterable)
    Iterable是否为空
    static boolean
    isNotEmpty(Collection<?> collection)
    集合是否为非空
    static boolean
    isNotEmpty(Enumeration<?> enumeration)
    Enumeration是否为空
    static boolean
    isNotEmpty(Iterator<?> Iterator)
    Iterator是否为空
    static boolean
    isNotEmpty(Map<?,?> map)
    Map是否为非空
    static <T> String
    join(Iterable<T> iterable, CharSequence conjunction)
    以 conjunction 为分隔符将集合转换为字符串 如果集合元素为数组、IterableIterator,则递归组合其为字符串
    static <T> String
    join(Iterable<T> iterable, CharSequence conjunction, String prefix, String suffix)
    以 conjunction 为分隔符将集合转换为字符串
    static <T> String
    join(Iterable<T> iterable, CharSequence conjunction, Function<T,? extends CharSequence> func)
    以 conjunction 为分隔符将集合转换为字符串
    static <T> String
    join(Iterator<T> iterator, CharSequence conjunction)
    以 conjunction 为分隔符将集合转换为字符串 如果集合元素为数组、IterableIterator,则递归组合其为字符串
    static <T> Collector<T,?,String>
    joining(CharSequence delimiter)
    提供任意对象的Join操作的Collector实现,对象默认调用toString方法
    static <T> Collector<T,?,String>
    joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix, Function<T,? extends CharSequence> toStringFunc)
    提供任意对象的Join操作的Collector实现
    static <T> Collector<T,?,String>
    joining(CharSequence delimiter, Function<T,? extends CharSequence> toStringFunc)
    提供任意对象的Join操作的Collector实现
    static <K> Set<K>
    keySet(Collection<Map<K,?>> mapCollection)
    获取指定Map列表中所有的Key
    static <T> int
    lastIndexOf(Collection<T> collection, Matcher<T> matcher)
    获取匹配规则定义中匹配到元素的最后位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
    static <T> int
    lastIndexOf(List<T> list, Matcher<T> matcher)
    获取匹配规则定义中匹配到元素的最后位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
    static <T> List<T>
    list(boolean isLinked)
    新建一个空List
    static <T> List<T>
    list(boolean isLinked, Iterable<T> iterable)
    新建一个List 提供的参数为null时返回空ArrayList
    static <T> List<T>
    list(boolean isLinked, Collection<T> collection)
    新建一个List
    static <T> List<T>
    list(boolean isLinked, Enumeration<T> enumration)
    新建一个List 提供的参数为null时返回空ArrayList
    static <T> List<T>
    list(boolean isLinked, Iterator<T> iter)
    新建一个List 提供的参数为null时返回空ArrayList
    static <T> List<T>
    list(boolean isLinked, T... values)
    新建一个List
    static <T, R> List<R>
    map(Iterable<T> collection, Function<? super T,? extends R> func, boolean ignoreNull)
    通过func自定义一个规则,此规则将原集合中的元素转换成新的元素,生成新的列表返回 例如提供的是一个Bean列表,通过Function接口实现获取某个字段值,返回这个字段值组成的新列表
    static <K, V, M extends Map<K, V>>
    BinaryOperator<M>
    mapMerger(BinaryOperator<V> mergeFunction)
    用户合并map的BinaryOperator,传入合并前需要对value进行的操作
    static <T extends Comparable<? super T>>
    T
    max(Collection<T> coll)
    取最大值
    static <K, X, Y, V> Map<K,V>
    merge(Map<K,X> map1, Map<K,Y> map2, BiFunction<X,Y,V> merge)
    合并两个相同key类型的map
    static <T extends Comparable<? super T>>
    T
    min(Collection<T> coll)
    取最小值
    static <T> ArrayList<T>
    newArrayList(Iterable<T> iterable)
    新建一个ArrayList 提供的参数为null时返回空ArrayList
    static <T> ArrayList<T>
    newArrayList(Collection<T> collection)
    新建一个ArrayList
    static <T> ArrayList<T>
    newArrayList(Enumeration<T> enumration)
    新建一个ArrayList 提供的参数为null时返回空ArrayList
    static <T> ArrayList<T>
    新建一个ArrayList 提供的参数为null时返回空ArrayList
    static <T> ArrayList<T>
    newArrayList(T... values)
    新建一个ArrayList
    static <T> BlockingQueue<T>
    newBlockingQueue(int capacity, boolean isLinked)
    新建BlockingQueue 在队列为空时,获取元素的线程会等待队列变为非空 当队列满时,存储元素的线程会等待队列可用
    static <T> CopyOnWriteArrayList<T>
    新建一个CopyOnWriteArrayList
    static <T> HashSet<T>
    newHashSet(boolean isSorted, Collection<T> collection)
    新建一个HashSet
    static <T> HashSet<T>
    newHashSet(boolean isSorted, Enumeration<T> enumration)
    新建一个HashSet
    static <T> HashSet<T>
    newHashSet(boolean isSorted, Iterator<T> iter)
    新建一个HashSet
    static <T> HashSet<T>
    newHashSet(boolean isSorted, T... ts)
    新建一个HashSet
    static <T> HashSet<T>
    newHashSet(Collection<T> collection)
    新建一个HashSet
    static <T> HashSet<T>
    newHashSet(T... ts)
    新建一个HashSet
    static <T> LinkedHashSet<T>
    新建一个LinkedHashSet
    static <T> LinkedList<T>
    newLinkedList(T... values)
    新建LinkedList
    static <T> List<T>
    of(T... ts)
    像java11一样获取一个List
    static <E> List<E>
    ofImmutableList(E... es)
    不可变 List
    static <E> Set<E>
    ofImmutableSet(E... es)
    不可变 Set
    static <T> void
    padLeft(List<T> list, int minLen, T padObj)
    填充List,以达到最小长度
    static <T> void
    padRight(Collection<T> list, int minLen, T padObj)
    填充List,以达到最小长度
    static <T> List<T>
    page(int pageNo, int pageSize, List<T> list)
    对指定List分页取值
    static <T> List<T>
    popPart(Deque<T> surplusAlaDatas, int partSize)
    切取部分数据 切取后的栈将减少这些元素
    static <T> List<T>
    popPart(Stack<T> surplusAlaDatas, int partSize)
    切取部分数据 切取后的栈将减少这些元素
    static int[]
    rainbow(int currentPage, int pageCount)
    分页彩虹算法(默认展示10页)
    static int[]
    rainbow(int currentPage, int pageCount, int displayCount)
    分页彩虹算法 通过传入的信息,生成一个分页列表显示
    static <T> Collection<T>
    removeAny(Collection<T> collection, T... elesRemoved)
    去掉集合中的多个元素
    static <T extends CharSequence>
    Collection<T>
    removeBlank(Collection<T> collection)
    去除null或者""或者空白字符串 元素
    static <T extends CharSequence>
    Collection<T>
    removeEmpty(Collection<T> collection)
    去除null或者"" 元素
    static <T> Collection<T>
    removeNull(Collection<T> collection)
    去除null 元素
    static <T extends Collection<E>, E>
    List<E>
    removeWithAddIf(T targetCollection, Predicate<? super E> predicate)
    移除集合中的多个元素,并将结果存放到生成的新集合中后返回 此方法直接修改原集合
    static <T extends Collection<E>, E>
    T
    removeWithAddIf(T targetCollection, T resultCollection, Predicate<? super E> predicate)
    移除集合中的多个元素,并将结果存放到指定的集合 此方法直接修改原集合
    static <T> List<T>
    reverse(List<T> list)
    反序给定List,会在原List基础上直接修改
    static <T> List<T>
    reverse(List<T> list, boolean clone)
    反序给定List,会创建一个新的List,原List数据不变
    static int
    ringNextInt(int modulo, AtomicInteger atomicInteger)
    通过cas操作 实现对指定值内的回环累加
    static int
    ringNextIntByObject(Object object, AtomicInteger atomicInteger)
    通过cas操作 实现对指定值内的回环累加
    static long
    ringNextLong(long modulo, AtomicLong atomicLong)
    通过cas操作 实现对指定值内的回环累加 此方法一般用于大量数据完成回环累加(如数据库中的值大于int最大值)
    static boolean
    safeContains(Collection<?> collection, Object value)
    判断指定集合是否包含指定值,如果集合为空(null或者空),返回false,否则找到元素返回true
    static <T> List<T>
    setOrAppend(List<T> list, int index, T element)
    设置或增加元素 当index小于List的长度时,替换指定位置的值,否则在尾部追加
    static <T> List<T>
    setOrPadding(List<T> list, int index, T element)
    在指定位置设置元素。当index小于List的长度时,替换指定位置的值,否则追加null直到到达index后,设置值
    static <T> List<T>
    setOrPadding(List<T> list, int index, T element, T paddingElement)
    在指定位置设置元素。当index小于List的长度时,替换指定位置的值,否则追加paddingElement直到到达index后,设置值
    static int
    size(Object object)
    获取Collection或者iterator的大小,此方法可以处理的对象类型如下: Collection - the collection size Map - the map size Array - the array size Iterator - the number of elements remaining in the iterator Enumeration - the number of elements remaining in the enumeration
    static <T> List<T>
    sort(Collection<T> collection, Comparator<? super T> comparator)
    排序集合,排序不会修改原集合
    static <E> void
    sort(List<E> list, boolean asc, String... name)
    对list的元素按照多个属性名称排序, list元素的属性可以是数字(byte、short、int、long、float、double等,支持正数、负数、0)、char、String、java.util.Date
    static <E> void
    sort(List<E> list, String[] name, boolean[] type)
    给list的每个属性都指定是升序还是降序
    static <T> List<T>
    sort(List<T> list, Comparator<? super T> c)
    针对List排序,排序会修改原List
    static <K, V> TreeMap<K,V>
    sort(Map<K,V> map, Comparator<? super K> comparator)
    排序Map
    static <K, V> LinkedHashMap<K,V>
    sortByEntry(Map<K,V> map, Comparator<Map.Entry<K,V>> comparator)
    通过Entry排序,可以按照键排序,也可以按照值排序,亦或者两者综合排序
    static List<String>
    根据汉字的拼音顺序排序
    static <T> List<T>
    sortByProperty(Collection<T> collection, String property)
    根据Bean的属性排序
    static <T> List<T>
    sortByProperty(List<T> list, String property)
    根据Bean的属性排序
    static <K, V> List<Map.Entry<K,V>>
    将Set排序(根据Entry的值)
    static <T> List<T>
    sortPageAll(int pageNo, int pageSize, Comparator<T> comparator, Collection<T>... colls)
    将多个集合排序并显示不同的段落(分页) 实现分页取局部
    static <K, V> LinkedHashMap<K,V>
    sortToMap(Collection<Map.Entry<K,V>> entryCollection, Comparator<Map.Entry<K,V>> comparator)
    通过Entry排序,可以按照键排序,也可以按照值排序,亦或者两者综合排序
    static <T> List<List<T>>
    split(Collection<T> collection, int size)
    对集合按照指定长度分段,每一个段为单独的集合,返回这个集合的列表
    static <T> List<List<T>>
    split(List<T> list, int size)
    对集合按照指定长度分段,每一个段为单独的集合,返回这个集合的列表
    static <T> List<List<T>>
    splitAvg(List<T> list, int limit)
    将集合平均分成多个list,返回这个集合的列表
    static <T> List<T>
    sub(Collection<T> collection, int start, int end)
    截取集合的部分
    static <T> List<T>
    sub(Collection<T> list, int start, int end, int step)
    截取集合的部分
    static <T> List<T>
    sub(List<T> list, int start, int end)
    截取集合的部分
    static <T> List<T>
    sub(List<T> list, int start, int end, int step)
    截取集合的部分 与List.subList(int, int) 不同在于子列表是新的副本,操作子列表不会影响源列表
    static <T> Collection<T>
    subtract(Collection<T> coll1, Collection<T> coll2)
    计算集合的单差集,即只返回【集合1】中有,但是【集合2】中没有的元素,例如:
    static <T> List<T>
    subtractToList(Collection<T> coll1, Collection<T> coll2)
    计算集合的单差集,即只返回【集合1】中有,但是【集合2】中没有的元素 例如:
    static <T> void
    swapElement(List<T> list, T element, T targetElement)
    将指定元素交换到指定元素位置,其他元素的索引值不变 交换会修改原List如果集合中有多个相同元素,只交换第一个找到的元素
    static <T> void
    swapTo(List<T> list, T element, Integer targetIndex)
    将指定元素交换到指定索引位置,其他元素的索引值不变 交换会修改原List如果集合中有多个相同元素,只交换第一个找到的元素
    static <E> Collection<E>
    toCollection(Iterable<E> iterable)
    Iterable转为Collection 首先尝试强转,强转失败则构建一个新的ArrayList
    static <T> CopyOnWriteArrayList<T>
    新建一个CopyOnWriteArrayList
    static <V, K> Map<K,V>
    toIdentityMap(Collection<V> collection, Function<V,K> key)
    将collection转化为类型不变的map Collection<V> ----> Map<K,V>
    static <V, K> Map<K,V>
    toIdentityMap(Collection<V> collection, Function<V,K> key, boolean isParallel)
    将collection转化为类型不变的map Collection<V> ----> Map<K,V>
    static <T> LinkedList<T>
    toLinkedList(T... values)
    新建LinkedList
    static <T> ArrayList<T>
    toList(Iterable<T> iterable)
    新建一个ArrayList 提供的参数为null时返回空ArrayList
    static <E, T> List<T>
    toList(Collection<E> collection, Function<E,T> function)
    将collection转化为List集合,但是两者的泛型不同 Collection<E> ------> List<T>
    static <E, T> List<T>
    toList(Collection<E> collection, Function<E,T> function, boolean isParallel)
    将collection转化为List集合,但是两者的泛型不同 Collection<E> ------> List<T>
    static <T> ArrayList<T>
    toList(Collection<T> collection)
    新建一个ArrayList
    static <T> ArrayList<T>
    toList(Enumeration<T> enumeration)
    新建一个ArrayList 提供的参数为null时返回空ArrayList
    static <T> ArrayList<T>
    toList(Iterator<T> iterator)
    新建一个ArrayList 提供的参数为null时返回空ArrayList
    static <T> ArrayList<T>
    toList(T... values)
    新建一个ArrayList
    static <K, V> Map<K,List<V>>
    toListMap(Iterable<? extends Map<K,V>> mapList)
    行转列,合并相同的键,值合并为列表 将Map列表中相同key的值组成列表做为Map的value 是toMapList(Map)的逆方法 比如传入数据:
    static <K, V> HashMap<K,V>
    toMap(Iterable<Map.Entry<K,V>> entryIter)
    将Entry集合转换为HashMap
    toMap(Object[] array)
    将数组转换为Map(HashMap),支持数组元素类型为:
    static <E, K, V> Map<K,V>
    toMap(Collection<E> collection, Function<E,K> key, Function<E,V> value)
    将Collection转化为map(value类型与collection的泛型不同) Collection<E> -----> Map<K,V>
    static <E, K, V> Map<K,V>
    toMap(Collection<E> collection, Function<E,K> key, Function<E,V> value, boolean isParallel)
     
    static <T, K, U> Collector<T,?,Map<K,U>>
    toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
    对null友好的 toMap 操作的 Collector实现,默认使用HashMap
    static <T, K, U, M extends Map<K, U>>
    Collector<T,?,M>
    toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier)
    对null友好的 toMap 操作的 Collector实现
    static <K, V> List<Map<K,V>>
    toMapList(Map<K,? extends Iterable<V>> listMap)
    列转行 将Map中值列表分别按照其位置与key组成新的map 是toListMap(Iterable)的逆方法 比如传入数据:
    static <E, T> Set<T>
    toSet(Collection<E> collection, Function<E,T> function)
    将collection转化为Set集合,但是两者的泛型不同 Collection<E> ------> Set<T>
    static <E, T> Set<T>
    toSet(Collection<E> collection, Function<E,T> function, boolean isParallel)
    将collection转化为Set集合,但是两者的泛型不同 Collection<E> ------> Set<T>
    static int
    totalPage(int totalCount, int pageSize)
    根据总数计算总页数
    static <T> TreeSet<T>
    toTreeSet(Collection<T> collection, Comparator<T> comparator)
    将集合转换为排序后的TreeSet
    static <F, T> Collection<T>
    trans(Collection<F> collection, Function<? super F,? extends T> function)
    使用给定的转换函数,转换源集合为新类型的集合
    static int[]
    transToStartEnd(int pageNo, int pageSize)
    将页数和每页条目数转换为开始位置和结束位置 此方法用于不包括结束位置的分页方法 例如: 页码:1,每页10 = [0, 10] 页码:2,每页10 = [10, 20]
    static <T> Collection<T>
    union(Collection<T> coll1, Collection<T> coll2)
    两个集合的并集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最多的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c],此结果中只保留了三个c
    static <T> Collection<T>
    union(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
    多个集合的并集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最多的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c],此结果中只保留了三个c
    static <T> List<T>
    unionAll(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
    多个集合的完全并集,类似于SQL中的“UNION ALL” 针对一个集合中存在多个相同元素的情况,保留全部元素 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c, a, b, c, c]
    static <T> Set<T>
    unionDistinct(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
    多个集合的非重复并集,类似于SQL中的“UNION DISTINCT” 针对一个集合中存在多个相同元素的情况,只保留一个 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c],此结果中只保留了一个c
    static <T> List<T>
    unmodifiable(List<T> list)
    将对应List转换为不可修改的List
    static <V> List<V>
    values(Collection<Map<?,V>> mapCollection)
    获取指定Map列表中所有的Value
    static <K, V> List<V>
    valuesOf(Map<K,V> map, Iterable<K> keys)
    从Map中获取指定键列表对应的值列表 如果key在map中不存在或key对应值为null,则返回值列表对应位置的值也为null
    static <K, V> List<V>
    valuesOf(Map<K,V> map, Iterator<K> keys)
    从Map中获取指定键列表对应的值列表 如果key在map中不存在或key对应值为null,则返回值列表对应位置的值也为null
    static <K, V> List<V>
    valuesOf(Map<K,V> map, K... keys)
    从Map中获取指定键列表对应的值列表 如果key在map中不存在或key对应值为null,则返回值列表对应位置的值也为null
    static <T> List<T>
    获取一个初始大小为0的List,这个空List可变
    static Map<String,String>
    zip(String keys, String values, String delimiter)
    映射键值(参考Python的zip()函数),返回Map无序 例如: keys = a,b,c,d values = 1,2,3,4 delimiter = , 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分
    static Map<String,String>
    zip(String keys, String values, String delimiter, boolean isOrder)
    映射键值(参考Python的zip()函数) 例如: keys = a,b,c,d values = 1,2,3,4 delimiter = , 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分
    static <K, V> Map<K,V>
    zip(Collection<K> keys, Collection<V> values)
    映射键值(参考Python的zip()函数) 例如: keys = [a,b,c,d] values = [1,2,3,4] 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CollKit

      public CollKit()
  • Method Details

    • isEmpty

      public static boolean isEmpty(Collection<?> collection)
      集合是否为空
      Parameters:
      collection - 集合
      Returns:
      是否为空
    • isEmpty

      public static boolean isEmpty(Map<?,?> map)
      Map是否为空
      Parameters:
      map - 集合
      Returns:
      是否为空
      See Also:
    • isEmpty

      public static boolean isEmpty(Iterable<?> iterable)
      Iterable是否为空
      Parameters:
      iterable - Iterable对象
      Returns:
      是否为空
      See Also:
    • isEmpty

      public static boolean isEmpty(Iterator<?> Iterator)
      Iterator是否为空
      Parameters:
      Iterator - Iterator对象
      Returns:
      是否为空
      See Also:
    • isEmpty

      public static boolean isEmpty(Enumeration<?> enumeration)
      Enumeration是否为空
      Parameters:
      enumeration - Enumeration
      Returns:
      是否为空
    • isNotEmpty

      public static boolean isNotEmpty(Collection<?> collection)
      集合是否为非空
      Parameters:
      collection - 集合
      Returns:
      是否为非空
    • isNotEmpty

      public static boolean isNotEmpty(Map<?,?> map)
      Map是否为非空
      Parameters:
      map - 集合
      Returns:
      是否为非空
      See Also:
    • isNotEmpty

      public static boolean isNotEmpty(Iterable<?> iterable)
      Iterable是否为空
      Parameters:
      iterable - Iterable对象
      Returns:
      是否为空
      See Also:
    • isNotEmpty

      public static boolean isNotEmpty(Iterator<?> Iterator)
      Iterator是否为空
      Parameters:
      Iterator - Iterator对象
      Returns:
      是否为空
      See Also:
    • isNotEmpty

      public static boolean isNotEmpty(Enumeration<?> enumeration)
      Enumeration是否为空
      Parameters:
      enumeration - Enumeration
      Returns:
      是否为空
    • isEqualList

      public static boolean isEqualList(Collection<?> list1, Collection<?> list2)
      判断两个Collection 是否元素和顺序相同,返回true的条件是: 此方法来自Apache-Commons-Collections4。
      Parameters:
      list1 - 列表1
      list2 - 列表2
      Returns:
      是否相同
    • hasNull

      public static boolean hasNull(Iterable<?> iterable)
      是否包含null元素
      Parameters:
      iterable - 被检查的Iterable对象,如果为null 返回true
      Returns:
      是否包含null元素
      See Also:
    • emptyIfNull

      public static <T> Set<T> emptyIfNull(Set<T> set)
      如果提供的集合为null,返回一个不可变的默认空集合,否则返回原集合 空集合使用Collections.emptySet()
      Type Parameters:
      T - 集合元素类型
      Parameters:
      set - 提供的集合,可能为null
      Returns:
      原集合,若为null返回空集合
    • emptyIfNull

      public static <T> List<T> emptyIfNull(List<T> list)
      如果提供的集合为null,返回一个不可变的默认空集合,否则返回原集合 空集合使用Collections.emptyList()
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 提供的集合,可能为null
      Returns:
      原集合,若为null返回空集合
    • defaultIfEmpty

      public static <T extends Collection<E>, E> T defaultIfEmpty(T collection, T defaultCollection)
      如果给定集合为空,返回默认集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      collection - 集合
      defaultCollection - 默认数组
      Returns:
      非空(empty)的原集合或默认集合
    • defaultIfEmpty

      public static <T extends Collection<E>, E> T defaultIfEmpty(T collection, Supplier<? extends T> supplier)
      如果给定集合为空,返回默认集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      collection - 集合
      supplier - 默认值懒加载函数
      Returns:
      非空(empty)的原集合或默认集合
    • empty

      public static <T> List<T> empty()
      获取一个空List,这个空List不可变
      Type Parameters:
      T - 元素类型
      Returns:
      空的List
      See Also:
    • zero

      public static <T> List<T> zero()
      获取一个初始大小为0的List,这个空List可变
      Type Parameters:
      T - 元素类型
      Returns:
      空的List
    • union

      public static <T> Collection<T> union(Collection<T> coll1, Collection<T> coll2)
      两个集合的并集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最多的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c],此结果中只保留了三个c
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      Returns:
      并集的集合, 返回 ArrayList
    • union

      public static <T> Collection<T> union(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
      多个集合的并集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最多的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c],此结果中只保留了三个c
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      otherColls - 其它集合
      Returns:
      并集的集合, 返回 ArrayList
    • unionDistinct

      public static <T> Set<T> unionDistinct(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
      多个集合的非重复并集,类似于SQL中的“UNION DISTINCT” 针对一个集合中存在多个相同元素的情况,只保留一个 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c],此结果中只保留了一个c
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      otherColls - 其它集合
      Returns:
      并集的集合,返回 LinkedHashSet
    • unionAll

      public static <T> List<T> unionAll(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
      多个集合的完全并集,类似于SQL中的“UNION ALL” 针对一个集合中存在多个相同元素的情况,保留全部元素 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c, a, b, c, c]
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      otherColls - 其它集合
      Returns:
      并集的集合,返回 ArrayList
    • intersection

      public static <T> Collection<T> intersection(Collection<T> coll1, Collection<T> coll2)
      两个集合的交集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最少的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c],此结果中只保留了两个c
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      Returns:
      并集的集合, 返回 ArrayList
    • intersection

      public static <T> Collection<T> intersection(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
      多个集合的交集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最少的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c],此结果中只保留了两个c
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      otherColls - 其它集合
      Returns:
      并集的集合, 返回 ArrayList
    • intersectOne

      public static <T> Set<T> intersectOne(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
      多个集合的交集 针对一个集合中存在多个相同元素的情况,只保留一个 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c],此结果中只保留了一个c
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      otherColls - 其它集合
      Returns:
      并集的集合,返回 LinkedHashSet
    • subtract

      public static <T> Collection<T> subtract(Collection<T> coll1, Collection<T> coll2)
      计算集合的单差集,即只返回【集合1】中有,但是【集合2】中没有的元素,例如:
           subtract([1,2,3,4],[2,3,4,5]) -  [1]
       
      Type Parameters:
      T - 元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      Returns:
      单差集
    • subtractToList

      public static <T> List<T> subtractToList(Collection<T> coll1, Collection<T> coll2)
      计算集合的单差集,即只返回【集合1】中有,但是【集合2】中没有的元素 例如:
           subtractToList([1,2,3,4],[2,3,4,5]) - [1]
       
      Type Parameters:
      T - 元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      Returns:
      单差集
    • disjunction

      public static <T> Collection<T> disjunction(Collection<T> coll1, Collection<T> coll2)
      两个集合的差集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留两个集合中此元素个数差的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[c],此结果中只保留了一个 任意一个集合为空,返回另一个集合 两个集合无交集则返回两个集合的组合
      Type Parameters:
      T - 集合元素类型
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      Returns:
      差集的集合, 返回 ArrayList
    • contains

      public static <T> boolean contains(T[] array, T element)
      检查给定数组是否包含给定元素
      Type Parameters:
      T - 通用标签
      Parameters:
      array - 数组要检查的数组
      element - 要查找的元素
      Returns:
      如果集合为空(null或者空), 返回false,否则找到元素返回true
    • contains

      public static boolean contains(Collection<?> collection, Object value)
      判断指定集合是否包含指定值,如果集合为空(null或者空),返回false,否则找到元素返回true
      Parameters:
      collection - 集合
      value - 需要查找的值
      Returns:
      如果集合为空(null或者空), 返回false,否则找到元素返回true
    • safeContains

      public static boolean safeContains(Collection<?> collection, Object value)
      判断指定集合是否包含指定值,如果集合为空(null或者空),返回false,否则找到元素返回true
      Parameters:
      collection - 集合
      value - 需要查找的值
      Returns:
      果集合为空(null或者空),返回false,否则找到元素返回true
    • contains

      public static boolean contains(Iterator<?> iterator, Object element)
      检查给定的迭代器是否包含给定的元素.
      Parameters:
      iterator - 要检查的迭代器
      element - 要查找的元素
      Returns:
      true 如果找到, false 否则返回
    • contains

      public static boolean contains(Enumeration<?> enumeration, Object element)
      检查给定枚举是否包含给定元素.
      Parameters:
      enumeration - 要检查的枚举
      element - 要查找的元素
      Returns:
      true 如果找到, false 否则返回
    • contains

      public static <T> boolean contains(Collection<T> collection, Predicate<? super T> containFunc)
      自定义函数判断集合是否包含某类值
      Type Parameters:
      T - 值类型
      Parameters:
      collection - 集合
      containFunc - 自定义判断函数
      Returns:
      是否包含自定义规则的值
    • containsAny

      public static boolean containsAny(Collection<?> coll1, Collection<?> coll2)
      其中一个集合在另一个集合中是否至少包含一个元素,既是两个集合是否至少有一个共同的元素
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      Returns:
      其中一个集合在另一个集合中是否至少包含一个元素
    • containsAll

      public static boolean containsAll(Collection<?> coll1, Collection<?> coll2)
      集合1中是否包含集合2中所有的元素,即集合2是否为集合1的子集
      Parameters:
      coll1 - 集合1
      coll2 - 集合2
      Returns:
      集合1中是否包含集合2中所有的元素
    • countMap

      public static <T> Map<T,Integer> countMap(Iterable<T> collection)
      根据集合返回一个元素计数的 Map 所谓元素计数就是假如这个集合中某个元素出现了n次,那将这个元素做为key,n做为value 例如:[a,b,c,c,c] 得到: a: 1 b: 1 c: 3
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      Map
      See Also:
    • join

      public static <T> String join(Iterable<T> iterable, CharSequence conjunction, Function<T,? extends CharSequence> func)
      以 conjunction 为分隔符将集合转换为字符串
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      conjunction - 分隔符
      func - 集合元素转换器,将元素转换为字符串
      Returns:
      连接后的字符串
    • join

      public static <T> String join(Iterable<T> iterable, CharSequence conjunction)
      以 conjunction 为分隔符将集合转换为字符串 如果集合元素为数组、IterableIterator,则递归组合其为字符串
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      conjunction - 分隔符
      Returns:
      连接后的字符串
      See Also:
    • join

      public static <T> String join(Iterator<T> iterator, CharSequence conjunction)
      以 conjunction 为分隔符将集合转换为字符串 如果集合元素为数组、IterableIterator,则递归组合其为字符串
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterator - 集合
      conjunction - 分隔符
      Returns:
      连接后的字符串
      See Also:
    • join

      public static <T> String join(Iterable<T> iterable, CharSequence conjunction, String prefix, String suffix)
      以 conjunction 为分隔符将集合转换为字符串
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      conjunction - 分隔符
      prefix - 每个元素添加的前缀,null表示不添加
      suffix - 每个元素添加的后缀,null表示不添加
      Returns:
      连接后的字符串
    • popPart

      public static <T> List<T> popPart(Stack<T> surplusAlaDatas, int partSize)
      切取部分数据 切取后的栈将减少这些元素
      Type Parameters:
      T - 集合元素类型
      Parameters:
      surplusAlaDatas - 原数据
      partSize - 每部分数据的长度
      Returns:
      切取出的数据或null
    • popPart

      public static <T> List<T> popPart(Deque<T> surplusAlaDatas, int partSize)
      切取部分数据 切取后的栈将减少这些元素
      Type Parameters:
      T - 集合元素类型
      Parameters:
      surplusAlaDatas - 原数据
      partSize - 每部分数据的长度
      Returns:
      切取出的数据或null
    • newHashSet

      public static <T> HashSet<T> newHashSet(T... ts)
      新建一个HashSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      ts - 元素数组
      Returns:
      HashSet对象
    • newLinkedHashSet

      public static <T> LinkedHashSet<T> newLinkedHashSet(T... ts)
      新建一个LinkedHashSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      ts - 元素数组
      Returns:
      HashSet对象
    • newHashSet

      public static <T> HashSet<T> newHashSet(boolean isSorted, T... ts)
      新建一个HashSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isSorted - 是否有序,有序返回 LinkedHashSet,否则返回 HashSet
      ts - 元素数组
      Returns:
      HashSet对象
    • newHashSet

      public static <T> HashSet<T> newHashSet(Collection<T> collection)
      新建一个HashSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      HashSet对象
    • newHashSet

      public static <T> HashSet<T> newHashSet(boolean isSorted, Collection<T> collection)
      新建一个HashSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isSorted - 是否有序,有序返回 LinkedHashSet,否则返回HashSet
      collection - 集合,用于初始化Set
      Returns:
      HashSet对象
    • newHashSet

      public static <T> HashSet<T> newHashSet(boolean isSorted, Iterator<T> iter)
      新建一个HashSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isSorted - 是否有序,有序返回 LinkedHashSet,否则返回HashSet
      iter - Iterator
      Returns:
      HashSet对象
    • newHashSet

      public static <T> HashSet<T> newHashSet(boolean isSorted, Enumeration<T> enumration)
      新建一个HashSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isSorted - 是否有序,有序返回 LinkedHashSet,否则返回HashSet
      enumration - Enumeration
      Returns:
      HashSet对象
    • newArrayList

      public static <T> ArrayList<T> newArrayList(T... values)
      新建一个ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      values - 数组
      Returns:
      ArrayList对象
    • newArrayList

      public static <T> ArrayList<T> newArrayList(Collection<T> collection)
      新建一个ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      ArrayList对象
    • newArrayList

      public static <T> ArrayList<T> newArrayList(Iterable<T> iterable)
      新建一个ArrayList 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      Returns:
      ArrayList对象
    • newArrayList

      public static <T> ArrayList<T> newArrayList(Iterator<T> iter)
      新建一个ArrayList 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iter - Iterator
      Returns:
      ArrayList对象
    • newArrayList

      public static <T> ArrayList<T> newArrayList(Enumeration<T> enumration)
      新建一个ArrayList 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      enumration - Enumeration
      Returns:
      ArrayList对象
    • newLinkedList

      public static <T> LinkedList<T> newLinkedList(T... values)
      新建LinkedList
      Type Parameters:
      T - 类型
      Parameters:
      values - 数组
      Returns:
      LinkedList
    • newCopyOnWriteArrayList

      public static <T> CopyOnWriteArrayList<T> newCopyOnWriteArrayList(Collection<T> collection)
      新建一个CopyOnWriteArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      CopyOnWriteArrayList
    • newBlockingQueue

      public static <T> BlockingQueue<T> newBlockingQueue(int capacity, boolean isLinked)
      新建BlockingQueue 在队列为空时,获取元素的线程会等待队列变为非空 当队列满时,存储元素的线程会等待队列可用
      Type Parameters:
      T - 对象
      Parameters:
      capacity - 容量
      isLinked - 是否为链表形式
      Returns:
      BlockingQueue
    • list

      public static <T> List<T> list(boolean isLinked)
      新建一个空List
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isLinked - 是否新建LinkedList
      Returns:
      List对象
    • list

      public static <T> List<T> list(boolean isLinked, T... values)
      新建一个List
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isLinked - 是否新建LinkedList
      values - 数组
      Returns:
      List对象
    • list

      public static <T> List<T> list(boolean isLinked, Collection<T> collection)
      新建一个List
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isLinked - 是否新建LinkedList
      collection - 集合
      Returns:
      List对象
    • list

      public static <T> List<T> list(boolean isLinked, Iterable<T> iterable)
      新建一个List 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isLinked - 是否新建LinkedList
      iterable - Iterable
      Returns:
      List对象
    • list

      public static <T> List<T> list(boolean isLinked, Iterator<T> iter)
      新建一个List 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isLinked - 是否新建LinkedList
      iter - Iterator
      Returns:
      ArrayList对象
    • list

      public static <T> List<T> list(boolean isLinked, Enumeration<T> enumration)
      新建一个List 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isLinked - 是否新建LinkedList
      enumration - Enumeration
      Returns:
      ArrayList对象
    • toList

      public static <T> ArrayList<T> toList(T... values)
      新建一个ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      values - 数组
      Returns:
      ArrayList对象
    • toLinkedList

      public static <T> LinkedList<T> toLinkedList(T... values)
      新建LinkedList
      Type Parameters:
      T - 类型
      Parameters:
      values - 数组
      Returns:
      LinkedList
    • toCopyOnWriteArrayList

      public static <T> CopyOnWriteArrayList<T> toCopyOnWriteArrayList(Collection<T> collection)
      新建一个CopyOnWriteArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      CopyOnWriteArrayList
    • toList

      public static <T> ArrayList<T> toList(Collection<T> collection)
      新建一个ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      ArrayList对象
    • toList

      public static <T> ArrayList<T> toList(Iterable<T> iterable)
      新建一个ArrayList 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      Returns:
      ArrayList对象
    • toList

      public static <T> ArrayList<T> toList(Iterator<T> iterator)
      新建一个ArrayList 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterator - Iterator
      Returns:
      ArrayList对象
    • toList

      public static <T> ArrayList<T> toList(Enumeration<T> enumeration)
      新建一个ArrayList 提供的参数为null时返回空ArrayList
      Type Parameters:
      T - 集合元素类型
      Parameters:
      enumeration - Enumeration
      Returns:
      ArrayList对象
    • indexOf

      public static <T> int indexOf(Collection<T> collection, Matcher<T> matcher)
      获取匹配规则定义中匹配到元素的第一个位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      matcher - 匹配器,为空则全部匹配
      Returns:
      第一个位置
    • lastIndexOf

      public static <T> int lastIndexOf(List<T> list, Matcher<T> matcher)
      获取匹配规则定义中匹配到元素的最后位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
      Type Parameters:
      T - 元素类型
      Parameters:
      list - List集合
      matcher - 匹配器,为空则全部匹配
      Returns:
      最后一个位置
    • lastIndexOf

      public static <T> int lastIndexOf(Collection<T> collection, Matcher<T> matcher)
      获取匹配规则定义中匹配到元素的最后位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      matcher - 匹配器,为空则全部匹配
      Returns:
      最后一个位置
    • indexOfAll

      public static <T> int[] indexOfAll(Collection<T> collection, Matcher<T> matcher)
      获取匹配规则定义中匹配到元素的所有位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      matcher - 匹配器,为空则全部匹配
      Returns:
      位置数组
    • unmodifiable

      public static <T> List<T> unmodifiable(List<T> list)
      将对应List转换为不可修改的List
      Type Parameters:
      T - 元素类型
      Parameters:
      list - List
      Returns:
      不可修改List
    • create

      public static <T> Collection<T> create(Class<?> collectionType)
      创建新的集合对象
      Type Parameters:
      T - 对象
      Parameters:
      collectionType - 集合类型
      Returns:
      集合类型对应的实例
    • createMap

      public static <K, V> Map<K,V> createMap(Class<?> mapType)
      创建Map 传入抽象MapAbstractMapMap类将默认创建HashMap
      Type Parameters:
      K - map键类型
      V - map值类型
      Parameters:
      mapType - map类型
      Returns:
      Map实例
      See Also:
    • distinct

      public static <T> List<T> distinct(Collection<T> collection)
      去重集合
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      List
    • distinct

      public static <T> Predicate<T> distinct(Function<? super T,?> key)
      去重集合
      Type Parameters:
      T - 集合元素类型
      Parameters:
      key - 属性名
      Returns:
      List
    • distinct

      public static <T, K> List<T> distinct(Collection<T> collection, Function<T,K> uniqueGenerator, boolean override)
      根据函数生成的KEY去重集合,如根据Bean的某个或者某些字段完成去重 去重可选是保留最先加入的值还是后加入的值
      Type Parameters:
      T - 集合元素类型
      K - 唯一键类型
      Parameters:
      collection - 集合
      override - 是否覆盖模式,如果为true,加入的新值会覆盖相同key的旧值,否则会忽略新加值
      Returns:
      ArrayList
    • sub

      public static <T> List<T> sub(List<T> list, int start, int end)
      截取集合的部分
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 被截取的数组
      start - 开始位置(包含)
      end - 结束位置(不包含)
      Returns:
      截取后的数组, 当开始位置超过最大时, 返回空的List
    • sub

      public static <T> List<T> sub(List<T> list, int start, int end, int step)
      截取集合的部分 与List.subList(int, int) 不同在于子列表是新的副本,操作子列表不会影响源列表
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 被截取的数组
      start - 开始位置(包含)
      end - 结束位置(不包含)
      step - 步进
      Returns:
      截取后的数组, 当开始位置超过最大时, 返回空的List
    • sub

      public static <T> List<T> sub(Collection<T> collection, int start, int end)
      截取集合的部分
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 被截取的数组
      start - 开始位置(包含)
      end - 结束位置(不包含)
      Returns:
      截取后的数组, 当开始位置超过最大时, 返回null
    • sub

      public static <T> List<T> sub(Collection<T> list, int start, int end, int step)
      截取集合的部分
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 被截取的数组
      start - 开始位置(包含)
      end - 结束位置(不包含)
      step - 步进
      Returns:
      截取后的数组, 当开始位置超过最大时, 返回空集合
    • split

      public static <T> List<List<T>> split(List<T> list, int size)
      对集合按照指定长度分段,每一个段为单独的集合,返回这个集合的列表
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 列表
      size - 每个段的长度
      Returns:
      分段列表
    • split

      public static <T> List<List<T>> split(Collection<T> collection, int size)
      对集合按照指定长度分段,每一个段为单独的集合,返回这个集合的列表
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      size - 每个段的长度
      Returns:
      分段列表
    • splitAvg

      public static <T> List<List<T>> splitAvg(List<T> list, int limit)
      将集合平均分成多个list,返回这个集合的列表
           CollKit.splitAvg(null, 3); // [[], [], []]
           CollKit.splitAvg(Arrays.asList(1, 2, 3, 4), 2);    // [[1, 2], [3, 4]]
           CollKit.splitAvg(Arrays.asList(1, 2, 3), 5);       // [[1], [2], [3], [], []]
           CollKit.splitAvg(Arrays.asList(1, 2, 3), 2);       // [[1, 2], [3]]
       
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 集合
      limit - 要均分成几个集合
      Returns:
      分段列表
    • filter

      public static <T> Collection<T> filter(Collection<T> collection, Editor<T> editor)
      过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
       1、过滤出需要的对象,如果返回null表示这个元素对象抛弃
       2、修改元素对象,返回集合中为修改后的对象
       
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      editor - 编辑器接口
      Returns:
      过滤后的数组
    • filter

      public static <T> List<T> filter(List<T> list, Editor<T> editor)
      过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
       1、过滤出需要的对象,如果返回null表示这个元素对象抛弃
       2、修改元素对象,返回集合中为修改后的对象
       
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 集合
      editor - 编辑器接口
      Returns:
      过滤后的数组
    • filter

      public static <T extends Iterable<E>, E> T filter(T iter, Filter<E> filter)
      过滤集合,此方法在原集合上直接修改 通过实现Filter接口,完成元素的过滤,这个Filter实现可以实现以下功能:
       1、过滤出需要的对象,Filter.accept(Object)方法返回false的对象将被使用Iterator.remove()方法移除
       
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      iter - 集合
      filter - 过滤器接口
      Returns:
      编辑后的集合
    • filter

      public static <E> Iterator<E> filter(Iterator<E> iter, Filter<E> filter)
      过滤集合,此方法在原集合上直接修改 通过实现Filter接口,完成元素的过滤,这个Filter实现可以实现以下功能:
       1、过滤出需要的对象,Filter.accept(Object)方法返回false的对象将被使用Iterator.remove()方法移除
       
      Type Parameters:
      E - 集合元素类型
      Parameters:
      iter - 集合
      filter - 过滤器接口
      Returns:
      编辑后的集合
    • removeNull

      public static <T> Collection<T> removeNull(Collection<T> collection)
      去除null 元素
      Type Parameters:
      T - 对象
      Parameters:
      collection - 集合
      Returns:
      处理后的集合
    • removeAny

      public static <T> Collection<T> removeAny(Collection<T> collection, T... elesRemoved)
      去掉集合中的多个元素
      Type Parameters:
      T - 对象
      Parameters:
      collection - 集合
      elesRemoved - 被去掉的元素数组
      Returns:
      原集合
    • removeEmpty

      public static <T extends CharSequence> Collection<T> removeEmpty(Collection<T> collection)
      去除null或者"" 元素
      Type Parameters:
      T - 对象
      Parameters:
      collection - 集合
      Returns:
      处理后的集合
    • removeBlank

      public static <T extends CharSequence> Collection<T> removeBlank(Collection<T> collection)
      去除null或者""或者空白字符串 元素
      Type Parameters:
      T - 对象
      Parameters:
      collection - 集合
      Returns:
      处理后的集合
    • removeWithAddIf

      public static <T extends Collection<E>, E> T removeWithAddIf(T targetCollection, T resultCollection, Predicate<? super E> predicate)
      移除集合中的多个元素,并将结果存放到指定的集合 此方法直接修改原集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      resultCollection - 存放移除结果的集合
      targetCollection - 被操作移除元素的集合
      predicate - 用于是否移除判断的过滤器
      Returns:
      移除结果的集合
    • removeWithAddIf

      public static <T extends Collection<E>, E> List<E> removeWithAddIf(T targetCollection, Predicate<? super E> predicate)
      移除集合中的多个元素,并将结果存放到生成的新集合中后返回 此方法直接修改原集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      targetCollection - 被操作移除元素的集合
      predicate - 用于是否移除判断的过滤器
      Returns:
      移除结果的集合
    • extract

      public static List<Object> extract(Iterable<?> collection, Editor<Object> editor)
      通过Editor抽取集合元素中的某些值返回为新列表 例如提供的是一个Bean列表,通过Editor接口实现获取某个字段值,返回这个字段值组成的新列表
      Parameters:
      collection - 原集合
      editor - 编辑器
      Returns:
      抽取后的新列表
    • extract

      public static List<Object> extract(Iterable<?> collection, Editor<Object> editor, boolean ignoreNull)
      通过Editor抽取集合元素中的某些值返回为新列表 例如提供的是一个Bean列表,通过Editor接口实现获取某个字段值,返回这个字段值组成的新列表
      Parameters:
      collection - 原集合
      editor - 编辑器
      ignoreNull - 是否忽略空值
      Returns:
      抽取后的新列表
      See Also:
    • map

      public static <T, R> List<R> map(Iterable<T> collection, Function<? super T,? extends R> func, boolean ignoreNull)
      通过func自定义一个规则,此规则将原集合中的元素转换成新的元素,生成新的列表返回 例如提供的是一个Bean列表,通过Function接口实现获取某个字段值,返回这个字段值组成的新列表
      Type Parameters:
      T - 输入类型
      R - 结果类型
      Parameters:
      collection - 原集合
      func - 编辑函数
      ignoreNull - 是否忽略空值,这里的空值包括函数处理前和处理后的null值
      Returns:
      抽取后的新列表
    • getFieldValues

      public static List<Object> getFieldValues(Iterable<?> collection, String fieldName)
      获取给定Bean列表中指定字段名对应字段值的列表 列表元素支持Bean与Map
      Parameters:
      collection - Bean集合或Map集合
      fieldName - 字段名或map的键
      Returns:
      字段值列表
    • findOne

      public static <T> T findOne(Iterable<T> collection, Filter<T> filter)
      查找第一个匹配元素对象
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      filter - 过滤器,满足过滤条件的第一个元素将被返回
      Returns:
      满足过滤条件的第一个元素
    • findOneByField

      public static <T> T findOneByField(Iterable<T> collection, String fieldName, Object fieldValue)
      查找第一个匹配元素对象 如果集合元素是Map,则比对键和值是否相同,相同则返回 如果为普通Bean,则通过反射比对元素字段名对应的字段值是否相同,相同则返回 如果给定字段值参数是null 且元素对象中的字段值也为null则认为相同
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合,集合元素可以是Bean或者Map
      fieldName - 集合元素对象的字段名或map的键
      fieldValue - 集合元素对象的字段值或map的值
      Returns:
      满足条件的第一个元素
    • filter

      public static <K, V> Map<K,V> filter(Map<K,V> map, Editor<Map.Entry<K,V>> editor)
      过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
       1、过滤出需要的对象,如果返回null表示这个元素对象抛弃
       2、修改元素对象,返回集合中为修改后的对象
       
      Type Parameters:
      K - Key类型
      V - Value类型
      Parameters:
      map - Map
      editor - 编辑器接口
      Returns:
      过滤后的Map
      See Also:
    • filter

      public static <K, V> Map<K,V> filter(Map<K,V> map, Filter<Map.Entry<K,V>> filter)
      过滤 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
       1、过滤出需要的对象,如果返回null表示这个元素对象抛弃
       2、修改元素对象,返回集合中为修改后的对象
       
      Type Parameters:
      K - Key类型
      V - Value类型
      Parameters:
      map - Map
      filter - 编辑器接口
      Returns:
      过滤后的Map
      See Also:
    • count

      public static <T> int count(Iterable<T> iterable, Matcher<T> matcher)
      集合中匹配规则的数量
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      matcher - 匹配器,为空则全部匹配
      Returns:
      匹配数量
    • zip

      public static Map<String,String> zip(String keys, String values, String delimiter, boolean isOrder)
      映射键值(参考Python的zip()函数) 例如: keys = a,b,c,d values = 1,2,3,4 delimiter = , 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分
      Parameters:
      keys - 键列表
      values - 值列表
      delimiter - 分隔符
      isOrder - 是否有序
      Returns:
      Map
    • zip

      public static Map<String,String> zip(String keys, String values, String delimiter)
      映射键值(参考Python的zip()函数),返回Map无序 例如: keys = a,b,c,d values = 1,2,3,4 delimiter = , 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分
      Parameters:
      keys - 键列表
      values - 值列表
      delimiter - 分隔符
      Returns:
      Map
    • zip

      public static <K, V> Map<K,V> zip(Collection<K> keys, Collection<V> values)
      映射键值(参考Python的zip()函数) 例如: keys = [a,b,c,d] values = [1,2,3,4] 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      keys - 键列表
      values - 值列表
      Returns:
      Map
    • toMap

      public static <K, V> HashMap<K,V> toMap(Iterable<Map.Entry<K,V>> entryIter)
      将Entry集合转换为HashMap
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      entryIter - entry集合
      Returns:
      Map
      See Also:
    • toMap

      public static HashMap<Object,Object> toMap(Object[] array)
      将数组转换为Map(HashMap),支持数组元素类型为:
       Map.Entry
       长度大于1的数组(取前两个值),如果不满足跳过此元素
       Iterable 长度也必须大于1(取前两个值),如果不满足跳过此元素
       Iterator 长度也必须大于1(取前两个值),如果不满足跳过此元素
       
       Map<Object, Object> colorMap = toMap(new String[][] {{
           {"RED", "#FF0000"},
           {"GREEN", "#00FF00"},
           {"BLUE", "#0000FF"}});
       

      参考:commons-lang

      Parameters:
      array - 数组 元素类型为Map.Entry、数组、Iterable、Iterator
      Returns:
      HashMap
      See Also:
    • toMap

      public static <E, K, V> Map<K,V> toMap(Collection<E> collection, Function<E,K> key, Function<E,V> value)
      将Collection转化为map(value类型与collection的泛型不同) Collection<E> -----> Map<K,V>
      Type Parameters:
      E - collection中的泛型
      K - map中的key类型
      V - map中的value类型
      Parameters:
      collection - 需要转化的集合
      key - E类型转化为K类型的lambda方法
      value - E类型转化为V类型的lambda方法
      Returns:
      转化后的map
    • toMap

      public static <E, K, V> Map<K,V> toMap(Collection<E> collection, Function<E,K> key, Function<E,V> value, boolean isParallel)
      Type Parameters:
      E - collection中的泛型
      K - map中的key类型
      V - map中的value类型
      Parameters:
      collection - 需要转化的集合
      key - E类型转化为K类型的lambda方法
      value - E类型转化为V类型的lambda方法
      isParallel - 是否并行流
      Returns:
      转化后的map
    • toMap

      public static <T, K, U> Collector<T,?,Map<K,U>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
      对null友好的 toMap 操作的 Collector实现,默认使用HashMap
      Type Parameters:
      T - 实体类型
      K - map中key的类型
      U - map中value的类型
      Parameters:
      keyMapper - 指定map中的key
      valueMapper - 指定map中的value
      mergeFunction - 合并前对value进行的操作
      Returns:
      对null友好的 toMap 操作的 Collector实现
    • toMap

      public static <T, K, U, M extends Map<K, U>> Collector<T,?,M> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier)
      对null友好的 toMap 操作的 Collector实现
      Type Parameters:
      T - 实体类型
      K - map中key的类型
      U - map中value的类型
      M - map的类型
      Parameters:
      keyMapper - 指定map中的key
      valueMapper - 指定map中的value
      mergeFunction - 合并前对value进行的操作
      mapSupplier - 最终需要的map类型
      Returns:
      对null友好的 toMap 操作的 Collector实现
    • toTreeSet

      public static <T> TreeSet<T> toTreeSet(Collection<T> collection, Comparator<T> comparator)
      将集合转换为排序后的TreeSet
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      comparator - 比较器
      Returns:
      treeSet
    • asEnumeration

      public static <E> Enumeration<E> asEnumeration(Iterator<E> iter)
      Iterator转换为Enumeration

      Adapt the specified Iterator to the Enumeration interface.

      Type Parameters:
      E - 集合元素类型
      Parameters:
      iter - Iterator
      Returns:
      Enumeration
    • asIterator

      public static <E> Iterator<E> asIterator(Enumeration<E> e)
      Enumeration转换为Iterator

      Adapt the specified Enumeration to the Iterator interface

      Type Parameters:
      E - 集合元素类型
      Parameters:
      e - Enumeration
      Returns:
      Iterator
      See Also:
    • asIterable

      public static <E> Iterable<E> asIterable(Iterator<E> iter)
      Type Parameters:
      E - 元素类型
      Parameters:
      iter - Iterator
      Returns:
      Iterable
      See Also:
    • toCollection

      public static <E> Collection<E> toCollection(Iterable<E> iterable)
      Iterable转为Collection 首先尝试强转,强转失败则构建一个新的ArrayList
      Type Parameters:
      E - 集合元素类型
      Parameters:
      iterable - Iterable
      Returns:
      Collection 或者 ArrayList
    • toListMap

      public static <K, V> Map<K,List<V>> toListMap(Iterable<? extends Map<K,V>> mapList)
      行转列,合并相同的键,值合并为列表 将Map列表中相同key的值组成列表做为Map的value 是toMapList(Map)的逆方法 比如传入数据:
       [
        {a: 1, b: 1, c: 1}
        {a: 2, b: 2}
        {a: 3, b: 3}
        {a: 4}
       ]
       

      结果是:

       {
         a: [1,2,3,4]
         b: [1,2,3,]
         c: [1]
       }
       
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      mapList - Map列表
      Returns:
      Map
      See Also:
    • toMapList

      public static <K, V> List<Map<K,V>> toMapList(Map<K,? extends Iterable<V>> listMap)
      列转行 将Map中值列表分别按照其位置与key组成新的map 是toListMap(Iterable)的逆方法 比如传入数据:
       {
         a: [1,2,3,4]
         b: [1,2,3,]
         c: [1]
       }
       

      结果是:

       [
        {a: 1, b: 1, c: 1}
        {a: 2, b: 2}
        {a: 3, b: 3}
        {a: 4}
       ]
       
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      listMap - 列表Map
      Returns:
      Map列表
      See Also:
    • addAll

      public static <T> Collection<T> addAll(Collection<T> collection, Object value)
      将指定对象全部加入到集合中 提供的对象如果为集合类型,会自动转换为目标元素类型
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 被加入的集合
      value - 对象,可能为Iterator、Iterable、Enumeration、Array
      Returns:
      被加入集合
    • addAll

      public static <T> Collection<T> addAll(Collection<T> collection, Object value, Type elementType)
      将指定对象全部加入到集合中 提供的对象如果为集合类型,会自动转换为目标元素类型
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 被加入的集合
      value - 对象,可能为Iterator、Iterable、Enumeration、Array,或者与集合元素类型一致
      elementType - 元素类型,为空时,使用Object类型来接纳所有类型
      Returns:
      被加入集合
    • addAll

      public static <T> Collection<T> addAll(Collection<T> collection, Iterator<T> iterator)
      加入全部
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 被加入的集合 Collection
      iterator - 要加入的Iterator
      Returns:
      原集合
    • addAll

      public static <T> Collection<T> addAll(Collection<T> collection, Iterable<T> iterable)
      加入全部
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 被加入的集合 Collection
      iterable - 要加入的内容Iterable
      Returns:
      原集合
    • addAll

      public static <T> Collection<T> addAll(Collection<T> collection, Enumeration<T> enumeration)
      加入全部
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 被加入的集合 Collection
      enumeration - 要加入的内容Enumeration
      Returns:
      原集合
    • addAll

      public static <T> Collection<T> addAll(Collection<T> collection, T[] values)
      加入全部
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 被加入的集合 Collection
      values - 要加入的内容数组
      Returns:
      原集合
    • addAll

      public static List<String> addAll(List<String> list, String part, boolean isTrim, boolean ignoreEmpty)
      将字符串加入List中
      Parameters:
      list - 列表
      part - 被加入的部分
      isTrim - 是否去除两端空白符
      ignoreEmpty - 是否略过空字符串(空字符串不做为一个元素)
      Returns:
      列表
    • addAllIfNotContains

      public static <T> List<T> addAllIfNotContains(List<T> list, List<T> otherList)
      将另一个列表中的元素加入到列表中,如果列表中已经存在此元素则忽略之
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 列表
      otherList - 其它列表
      Returns:
      此列表
    • get

      public static <T> T get(Collection<T> collection, int index)
      获取集合中指定下标的元素值,下标可以为负数,例如-1表示最后一个元素 如果元素越界,返回null
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      index - 下标,支持负数
      Returns:
      元素值
    • getAny

      public static <T> List<T> getAny(Collection<T> collection, int... indexes)
      获取集合中指定多个下标的元素值,下标可以为负数,例如-1表示最后一个元素
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      indexes - 下标,支持负数
      Returns:
      元素值列表
    • getFirst

      public static <T> T getFirst(Iterable<T> iterable)
      获取集合的第一个元素
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      Returns:
      第一个元素
      See Also:
    • getFirst

      public static <T> T getFirst(Iterator<T> iterator)
      获取集合的第一个元素
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterator - Iterator
      Returns:
      第一个元素
      See Also:
    • getLast

      public static <T> T getLast(Collection<T> collection)
      获取集合的最后一个元素
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - Collection
      Returns:
      最后一个元素
    • valuesOf

      public static <K, V> List<V> valuesOf(Map<K,V> map, K... keys)
      从Map中获取指定键列表对应的值列表 如果key在map中不存在或key对应值为null,则返回值列表对应位置的值也为null
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      map - Map
      keys - 键列表
      Returns:
      值列表
    • valuesOf

      public static <K, V> List<V> valuesOf(Map<K,V> map, Iterable<K> keys)
      从Map中获取指定键列表对应的值列表 如果key在map中不存在或key对应值为null,则返回值列表对应位置的值也为null
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      map - Map
      keys - 键列表
      Returns:
      值列表
    • valuesOf

      public static <K, V> List<V> valuesOf(Map<K,V> map, Iterator<K> keys)
      从Map中获取指定键列表对应的值列表 如果key在map中不存在或key对应值为null,则返回值列表对应位置的值也为null
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      map - Map
      keys - 键列表
      Returns:
      值列表
    • page

      public static <T> List<T> page(int pageNo, int pageSize, List<T> list)
      对指定List分页取值
      Type Parameters:
      T - 集合元素类型
      Parameters:
      pageNo - 页码,从1开始计数,0和1效果相同
      pageSize - 每页的条目数
      list - 列表
      Returns:
      分页后的段落内容
    • sort

      public static <T> List<T> sort(Collection<T> collection, Comparator<? super T> comparator)
      排序集合,排序不会修改原集合
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      comparator - 比较器
      Returns:
      treeSet
    • sort

      public static <T> List<T> sort(List<T> list, Comparator<? super T> c)
      针对List排序,排序会修改原List
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 被排序的List
      c - Comparator
      Returns:
      原list
      See Also:
    • sort

      public static <K, V> TreeMap<K,V> sort(Map<K,V> map, Comparator<? super K> comparator)
      排序Map
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      map - Map
      comparator - Entry比较器
      Returns:
      TreeMap
    • sort

      public static <E> void sort(List<E> list, boolean asc, String... name)
      对list的元素按照多个属性名称排序, list元素的属性可以是数字(byte、short、int、long、float、double等,支持正数、负数、0)、char、String、java.util.Date
      Type Parameters:
      E - 对象
      Parameters:
      list - 集合
      name - list元素的属性名称
      asc - true升序,false降序
    • sort

      public static <E> void sort(List<E> list, String[] name, boolean[] type)
      给list的每个属性都指定是升序还是降序
      Type Parameters:
      E - 对象
      Parameters:
      list - 集合
      name - 参数数组
      type - 每个属性对应的升降序数组, true升序,false降序
    • sortPageAll

      public static <T> List<T> sortPageAll(int pageNo, int pageSize, Comparator<T> comparator, Collection<T>... colls)
      将多个集合排序并显示不同的段落(分页) 实现分页取局部
      Type Parameters:
      T - 集合元素类型
      Parameters:
      pageNo - 页码,从1开始计数,0和1效果相同
      pageSize - 每页的条目数
      comparator - 比较器
      colls - 集合数组
      Returns:
      分页后的段落内容
    • sortByProperty

      public static <T> List<T> sortByProperty(Collection<T> collection, String property)
      根据Bean的属性排序
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合,会被转换为List
      property - 属性名
      Returns:
      排序后的List
    • sortByProperty

      public static <T> List<T> sortByProperty(List<T> list, String property)
      根据Bean的属性排序
      Type Parameters:
      T - 元素类型
      Parameters:
      list - List
      property - 属性名
      Returns:
      排序后的List
    • sortByPinyin

      public static List<String> sortByPinyin(List<String> list)
      根据汉字的拼音顺序排序
      Parameters:
      list - List
      Returns:
      排序后的List
    • sortToMap

      public static <K, V> LinkedHashMap<K,V> sortToMap(Collection<Map.Entry<K,V>> entryCollection, Comparator<Map.Entry<K,V>> comparator)
      通过Entry排序,可以按照键排序,也可以按照值排序,亦或者两者综合排序
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      entryCollection - Entry集合
      comparator - Comparator
      Returns:
      LinkedList
    • sortByEntry

      public static <K, V> LinkedHashMap<K,V> sortByEntry(Map<K,V> map, Comparator<Map.Entry<K,V>> comparator)
      通过Entry排序,可以按照键排序,也可以按照值排序,亦或者两者综合排序
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      map - 被排序的Map
      comparator - Comparator
      Returns:
      LinkedList
    • sortEntryToList

      public static <K, V> List<Map.Entry<K,V>> sortEntryToList(Collection<Map.Entry<K,V>> collection)
      将Set排序(根据Entry的值)
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      collection - 被排序的Collection
      Returns:
      排序后的Set
    • group

      public static <T> List<List<T>> group(Collection<T> collection, CollKit.Hash<T> hash)
      分组,按照CollKit.Hash接口定义的hash算法,集合中的元素放入hash值对应的子列表中
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 被分组的集合
      hash - Hash值算法,决定元素放在第几个分组的规则
      Returns:
      分组后的集合
    • groupByField

      public static <T> List<List<T>> groupByField(Collection<T> collection, String fieldName)
      根据元素的指定字段名分组,非Bean都放在第一个分组中
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      fieldName - 元素Bean中的字段名,非Bean都放在第一个分组中
      Returns:
      分组列表
    • forEach

      public static <T> void forEach(Iterator<T> iterator, CollKit.Consumer<T> consumer)
      循环遍历 Iterator,使用CollKit.Consumer 接受遍历的每条数据,并针对每条数据做处理
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterator - Iterator
      consumer - CollKit.Consumer 遍历的每条数据处理器
    • forEach

      public static <T> void forEach(Enumeration<T> enumeration, CollKit.Consumer<T> consumer)
      循环遍历 Enumeration,使用CollKit.Consumer 接受遍历的每条数据,并针对每条数据做处理
      Type Parameters:
      T - 集合元素类型
      Parameters:
      enumeration - Enumeration
      consumer - CollKit.Consumer 遍历的每条数据处理器
    • forEach

      public static <K, V> void forEach(Map<K,V> map, CollKit.KVConsumer<K,V> kvConsumer)
      循环遍历Map,使用CollKit.KVConsumer 接受遍历的每条数据,并针对每条数据做处理
      Type Parameters:
      K - Key类型
      V - Value类型
      Parameters:
      map - Map
      kvConsumer - CollKit.KVConsumer 遍历的每条数据处理器
    • reverse

      public static <T> List<T> reverse(List<T> list)
      反序给定List,会在原List基础上直接修改
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 被反转的List
      Returns:
      反转后的List
    • reverse

      public static <T> List<T> reverse(List<T> list, boolean clone)
      反序给定List,会创建一个新的List,原List数据不变
      Type Parameters:
      T - 元素类型
      Parameters:
      list - 被反转的List
      clone - 是否克隆
      Returns:
      反转后的List
    • forceGetFieldValue

      public static Object forceGetFieldValue(Object object, String fieldName) throws Exception
      获取指定对象的指定属性值(去除private,protected的限制)
      Parameters:
      object - 属性名称所在的对象
      fieldName - 属性名称
      Returns:
      the object
      Throws:
      Exception - 异常
    • setOrAppend

      public static <T> List<T> setOrAppend(List<T> list, int index, T element)
      设置或增加元素 当index小于List的长度时,替换指定位置的值,否则在尾部追加
      Type Parameters:
      T - 对象
      Parameters:
      list - List列表
      index - 位置
      element - 新元素
      Returns:
      原List
    • setOrPadding

      public static <T> List<T> setOrPadding(List<T> list, int index, T element)
      在指定位置设置元素。当index小于List的长度时,替换指定位置的值,否则追加null直到到达index后,设置值
      Type Parameters:
      T - 元素类型
      Parameters:
      list - List列表
      index - 位置
      element - 新元素
      Returns:
      原List
    • setOrPadding

      public static <T> List<T> setOrPadding(List<T> list, int index, T element, T paddingElement)
      在指定位置设置元素。当index小于List的长度时,替换指定位置的值,否则追加paddingElement直到到达index后,设置值
      Type Parameters:
      T - 元素类型
      Parameters:
      list - List列表
      index - 位置
      element - 新元素
      paddingElement - 填充的值
      Returns:
      原List
    • transToStartEnd

      public static int[] transToStartEnd(int pageNo, int pageSize)
      将页数和每页条目数转换为开始位置和结束位置 此方法用于不包括结束位置的分页方法 例如: 页码:1,每页10 = [0, 10] 页码:2,每页10 = [10, 20]
      Parameters:
      pageNo - 页码(从1计数)
      pageSize - 每页条目数
      Returns:
      第一个数为开始位置, 第二个数为结束位置
    • totalPage

      public static int totalPage(int totalCount, int pageSize)
      根据总数计算总页数
      Parameters:
      totalCount - 总数
      pageSize - 每页数
      Returns:
      总页数
    • rainbow

      public static int[] rainbow(int currentPage, int pageCount, int displayCount)
      分页彩虹算法 通过传入的信息,生成一个分页列表显示
      Parameters:
      currentPage - 当前页
      pageCount - 总页数
      displayCount - 每屏展示的页数
      Returns:
      分页条
    • rainbow

      public static int[] rainbow(int currentPage, int pageCount)
      分页彩虹算法(默认展示10页)
      Parameters:
      currentPage - 当前页
      pageCount - 总页数
      Returns:
      分页条
    • firstNotNullElem

      public static <T> Optional<T> firstNotNullElem(Collection<T> list)
      找到第一个不为 null 的元素
      Type Parameters:
      T - 泛型
      Parameters:
      list - 列表
      Returns:
      不为 null 的元素
    • concat

      public static <T> T[] concat(T[] one, T[] other, Class<T> clazz)
      Concatenates 2 arrays
      Type Parameters:
      T - 对象
      Parameters:
      one - 数组1
      other - 数组2
      clazz - 数组类
      Returns:
      新数组
    • of

      public static <T> List<T> of(T... ts)
      像java11一样获取一个List
      Type Parameters:
      T - 对象类型
      Parameters:
      ts - 对象
      Returns:
      不可修改List
    • ofImmutableSet

      public static <E> Set<E> ofImmutableSet(E... es)
      不可变 Set
      Type Parameters:
      E - 泛型
      Parameters:
      es - 对象
      Returns:
      集合
    • ofImmutableList

      public static <E> List<E> ofImmutableList(E... es)
      不可变 List
      Type Parameters:
      E - 泛型
      Parameters:
      es - 对象
      Returns:
      集合
    • keySet

      public static <K> Set<K> keySet(Collection<Map<K,?>> mapCollection)
      获取指定Map列表中所有的Key
      Type Parameters:
      K - 键类型
      Parameters:
      mapCollection - Map列表
      Returns:
      key集合
    • values

      public static <V> List<V> values(Collection<Map<?,V>> mapCollection)
      获取指定Map列表中所有的Value
      Type Parameters:
      V - 值类型
      Parameters:
      mapCollection - Map列表
      Returns:
      Value集合
    • max

      public static <T extends Comparable<? super T>> T max(Collection<T> coll)
      取最大值
      Type Parameters:
      T - 元素类型
      Parameters:
      coll - 集合
      Returns:
      最大值
      See Also:
    • min

      public static <T extends Comparable<? super T>> T min(Collection<T> coll)
      取最小值
      Type Parameters:
      T - 元素类型
      Parameters:
      coll - 集合
      Returns:
      最小值
      See Also:
    • clear

      public static void clear(Collection<?>... collections)
      清除一个或多个集合内的元素,每个集合调用clear()方法
      Parameters:
      collections - 一个或多个集合
    • padLeft

      public static <T> void padLeft(List<T> list, int minLen, T padObj)
      填充List,以达到最小长度
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 列表
      minLen - 最小长度
      padObj - 填充的对象
    • padRight

      public static <T> void padRight(Collection<T> list, int minLen, T padObj)
      填充List,以达到最小长度
      Type Parameters:
      T - 集合元素类型
      Parameters:
      list - 列表
      minLen - 最小长度
      padObj - 填充的对象
    • trans

      public static <F, T> Collection<T> trans(Collection<F> collection, Function<? super F,? extends T> function)
      使用给定的转换函数,转换源集合为新类型的集合
      Type Parameters:
      F - 源元素类型
      T - 目标元素类型
      Parameters:
      collection - 集合
      function - 转换函数
      Returns:
      新类型的集合
    • size

      public static int size(Object object)
      获取Collection或者iterator的大小,此方法可以处理的对象类型如下:
      • Collection - the collection size
      • Map - the map size
      • Array - the array size
      • Iterator - the number of elements remaining in the iterator
      • Enumeration - the number of elements remaining in the enumeration
      Parameters:
      object - 可以为空的对象
      Returns:
      如果object为空则返回0
      Throws:
      IllegalArgumentException - 参数object不是Collection或者iterator
    • toIdentityMap

      public static <V, K> Map<K,V> toIdentityMap(Collection<V> collection, Function<V,K> key)
      将collection转化为类型不变的map Collection<V> ----> Map<K,V>
      Type Parameters:
      V - collection中的泛型
      K - map中的key类型
      Parameters:
      collection - 需要转化的集合
      key - V类型转化为K类型的lambda方法
      Returns:
      转化后的map
    • toIdentityMap

      public static <V, K> Map<K,V> toIdentityMap(Collection<V> collection, Function<V,K> key, boolean isParallel)
      将collection转化为类型不变的map Collection<V> ----> Map<K,V>
      Type Parameters:
      V - collection中的泛型
      K - map中的key类型
      Parameters:
      collection - 需要转化的集合
      key - V类型转化为K类型的lambda方法
      isParallel - 是否并行流
      Returns:
      转化后的map
    • groupByKey

      public static <E, K> Map<K,List<E>> groupByKey(Collection<E> collection, Function<E,K> key)
      将collection按照规则(比如有相同的班级id)分类成map Collection<E> -------> Map<K,List<E>>
      Type Parameters:
      E - collection中的泛型
      K - map中的key类型
      Parameters:
      collection - 需要分类的集合
      key - 键分组的规则
      Returns:
      分类后的map
    • groupByKey

      public static <E, K> Map<K,List<E>> groupByKey(Collection<E> collection, Function<E,K> key, boolean isParallel)
      将collection按照规则(比如有相同的班级id)分类成map Collection<E> -------> Map<K,List<E>>
      Type Parameters:
      E - collection中的泛型
      K - map中的key类型
      Parameters:
      collection - 需要分类的集合
      key - 键分组的规则
      isParallel - 是否并行流
      Returns:
      分类后的map
    • groupBy2Key

      public static <E, K, U> Map<K,Map<U,List<E>>> groupBy2Key(Collection<E> collection, Function<E,K> key1, Function<E,U> key2)
      将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,List<E>>>
      Type Parameters:
      E - 集合元素类型
      K - 第一个map中的key类型
      U - 第二个map中的key类型
      Parameters:
      collection - 需要分类的集合
      key1 - 第一个分类的规则
      key2 - 第二个分类的规则
      Returns:
      分类后的map
    • groupBy2Key

      public static <E, K, U> Map<K,Map<U,List<E>>> groupBy2Key(Collection<E> collection, Function<E,K> key1, Function<E,U> key2, boolean isParallel)
      将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,List<E>>>
      Type Parameters:
      E - 集合元素类型
      K - 第一个map中的key类型
      U - 第二个map中的key类型
      Parameters:
      collection - 需要分类的集合
      key1 - 第一个分类的规则
      key2 - 第二个分类的规则
      isParallel - 是否并行流
      Returns:
      分类后的map
    • group2Map

      public static <E, T, U> Map<T,Map<U,E>> group2Map(Collection<E> collection, Function<E,T> key1, Function<E,U> key2)
      将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,E>>
      Type Parameters:
      T - 第一个map中的key类型
      U - 第二个map中的key类型
      E - collection中的泛型
      Parameters:
      collection - 需要分类的集合
      key1 - 第一个分类的规则
      key2 - 第二个分类的规则
      Returns:
      分类后的map
    • group2Map

      public static <E, T, U> Map<T,Map<U,E>> group2Map(Collection<E> collection, Function<E,T> key1, Function<E,U> key2, boolean isParallel)
      将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map Collection<E> ---> Map<T,Map<U,E>>
      Type Parameters:
      T - 第一个map中的key类型
      U - 第二个map中的key类型
      E - collection中的泛型
      Parameters:
      collection - 需要分类的集合
      key1 - 第一个分类的规则
      key2 - 第二个分类的规则
      isParallel - 是否并行流
      Returns:
      分类后的map
    • groupKeyValue

      public static <E, K, V> Map<K,List<V>> groupKeyValue(Collection<E> collection, Function<E,K> key, Function<E,V> value)
      将collection按照规则(比如有相同的班级id)分类成map,map中的key为班级id,value为班级名 Collection<E> -------> Map<K,List<V>>
      Type Parameters:
      E - collection中的泛型
      K - map中的key类型
      V - List中的value类型
      Parameters:
      collection - 需要分类的集合
      key - 分类的规则
      value - 分类的规则
      Returns:
      分类后的map
    • groupKeyValue

      public static <E, K, V> Map<K,List<V>> groupKeyValue(Collection<E> collection, Function<E,K> key, Function<E,V> value, boolean isParallel)
      将collection按照规则(比如有相同的班级id)分类成map,map中的key为班级id,value为班级名 Collection<E> -------> Map<K,List<V>>
      Type Parameters:
      E - collection中的泛型
      K - map中的key类型
      V - List中的value类型
      Parameters:
      collection - 需要分类的集合
      key - 分类的规则
      value - 分类的规则
      isParallel - 是否并行流
      Returns:
      分类后的map
    • joining

      public static <T> Collector<T,?,String> joining(CharSequence delimiter)
      提供任意对象的Join操作的Collector实现,对象默认调用toString方法
      Type Parameters:
      T - 对象类型
      Parameters:
      delimiter - 分隔符
      Returns:
      Collector
    • joining

      public static <T> Collector<T,?,String> joining(CharSequence delimiter, Function<T,? extends CharSequence> toStringFunc)
      提供任意对象的Join操作的Collector实现
      Type Parameters:
      T - 对象类型
      Parameters:
      delimiter - 分隔符
      toStringFunc - 自定义指定对象转换为字符串的方法
      Returns:
      Collector
    • joining

      public static <T> Collector<T,?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix, Function<T,? extends CharSequence> toStringFunc)
      提供任意对象的Join操作的Collector实现
      Type Parameters:
      T - 对象类型
      Parameters:
      delimiter - 分隔符
      prefix - 前缀
      suffix - 后缀
      toStringFunc - 自定义指定对象转换为字符串的方法
      Returns:
      Collector
    • groupingBy

      public static <T, K> Collector<T,?,Map<K,List<T>>> groupingBy(Function<? super T,? extends K> classifier)
      提供对null值友好的groupingBy操作的Collector实现
      Type Parameters:
      T - 实体类型
      K - 实体中的分组依据对应类型,也是Map中key的类型
      Parameters:
      classifier - 分组依据
      Returns:
      Collector
    • groupingBy

      public static <T, K, A, D> Collector<T,?,Map<K,D>> groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
      提供对null值友好的groupingBy操作的Collector实现
      Type Parameters:
      T - 实体类型
      K - 实体中的分组依据对应类型,也是Map中key的类型
      D - 下游操作对应返回类型,也是Map中value的类型
      A - 下游操作在进行中间操作时对应类型
      Parameters:
      classifier - 分组依据
      downstream - 下游操作
      Returns:
      Collector
    • groupingBy

      public static <T, K, D, A, M extends Map<K, D>> Collector<T,?,M> groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
      提供对null值友好的groupingBy操作的Collector实现,可指定map类型
      Type Parameters:
      T - 实体类型
      K - 实体中的分组依据对应类型,也是Map中key的类型
      D - 下游操作对应返回类型,也是Map中value的类型
      A - 下游操作在进行中间操作时对应类型
      M - 最后返回结果Map类型
      Parameters:
      classifier - 分组依据
      mapFactory - 提供的map
      downstream - 下游操作
      Returns:
      Collector
    • mapMerger

      public static <K, V, M extends Map<K, V>> BinaryOperator<M> mapMerger(BinaryOperator<V> mergeFunction)
      用户合并map的BinaryOperator,传入合并前需要对value进行的操作
      Type Parameters:
      K - key的类型
      V - value的类型
      M - map
      Parameters:
      mergeFunction - 合并前需要对value进行的操作
      Returns:
      用户合并map的BinaryOperator
    • toList

      public static <E, T> List<T> toList(Collection<E> collection, Function<E,T> function)
      将collection转化为List集合,但是两者的泛型不同 Collection<E> ------> List<T>
      Type Parameters:
      E - collection中的泛型
      T - List中的泛型
      Parameters:
      collection - 需要转化的集合
      function - collection中的泛型转化为list泛型的lambda表达式
      Returns:
      转化后的list
    • toList

      public static <E, T> List<T> toList(Collection<E> collection, Function<E,T> function, boolean isParallel)
      将collection转化为List集合,但是两者的泛型不同 Collection<E> ------> List<T>
      Type Parameters:
      E - collection中的泛型
      T - List中的泛型
      Parameters:
      collection - 需要转化的集合
      function - collection中的泛型转化为list泛型的lambda表达式
      isParallel - 是否并行流
      Returns:
      转化后的list
    • toSet

      public static <E, T> Set<T> toSet(Collection<E> collection, Function<E,T> function)
      将collection转化为Set集合,但是两者的泛型不同 Collection<E> ------> Set<T>
      Type Parameters:
      E - collection中的泛型
      T - Set中的泛型
      Parameters:
      collection - 需要转化的集合
      function - collection中的泛型转化为set泛型的lambda表达式
      Returns:
      转化后的Set
    • toSet

      public static <E, T> Set<T> toSet(Collection<E> collection, Function<E,T> function, boolean isParallel)
      将collection转化为Set集合,但是两者的泛型不同 Collection<E> ------> Set<T>
      Type Parameters:
      E - collection中的泛型
      T - Set中的泛型
      Parameters:
      collection - 需要转化的集合
      function - collection中的泛型转化为set泛型的lambda表达式
      isParallel - 是否并行流
      Returns:
      转化后的Set
    • merge

      public static <K, X, Y, V> Map<K,V> merge(Map<K,X> map1, Map<K,Y> map2, BiFunction<X,Y,V> merge)
      合并两个相同key类型的map
      Type Parameters:
      K - map中的key类型
      X - 第一个 map的value类型
      Y - 第二个 map的value类型
      V - 最终map的value类型
      Parameters:
      map1 - 第一个需要合并的 map
      map2 - 第二个需要合并的 map
      merge - 合并的lambda,将key value1 value2合并成最终的类型,注意value可能为空的情况
      Returns:
      合并后的map
    • swapTo

      public static <T> void swapTo(List<T> list, T element, Integer targetIndex)
      将指定元素交换到指定索引位置,其他元素的索引值不变 交换会修改原List如果集合中有多个相同元素,只交换第一个找到的元素
      Type Parameters:
      T - 处理参数类型
      Parameters:
      list - 列表
      element - 需交换元素
      targetIndex - 目标索引
    • swapElement

      public static <T> void swapElement(List<T> list, T element, T targetElement)
      将指定元素交换到指定元素位置,其他元素的索引值不变 交换会修改原List如果集合中有多个相同元素,只交换第一个找到的元素
      Type Parameters:
      T - 处理参数类型
      Parameters:
      list - 列表
      element - 需交换元素
      targetElement - 目标元素
    • ringNextIntByObject

      public static int ringNextIntByObject(Object object, AtomicInteger atomicInteger)
      通过cas操作 实现对指定值内的回环累加
      Parameters:
      object - 集合
      • Collection - 集合的大小
      • Map - Map的大小
      • Array - 数组大小
      • Iterator - 迭代器中剩余的元素数
      • Enumeration - 枚举中剩余的元素数
      atomicInteger - 原子操作类
      Returns:
      索引位置
    • ringNextInt

      public static int ringNextInt(int modulo, AtomicInteger atomicInteger)
      通过cas操作 实现对指定值内的回环累加
      Parameters:
      modulo - 回环周期值
      atomicInteger - 原子操作类
      Returns:
      索引位置
    • ringNextLong

      public static long ringNextLong(long modulo, AtomicLong atomicLong)
      通过cas操作 实现对指定值内的回环累加 此方法一般用于大量数据完成回环累加(如数据库中的值大于int最大值)
      Parameters:
      modulo - 回环周期值
      atomicLong - 原子操作类
      Returns:
      索引位置