Class CollKit


public class CollKit extends CollectionStream
集合相关工具类 此工具方法针对CollectionIterable及其实现类封装的工具
Since:
Java 17+
Author:
Kimi Liu
  • 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)
    将指定对象全部加入到集合中 提供的对象如果为集合类型,会自动转换为目标元素类型 如果为String,支持类似于[1,2,3,4] 或者 1,2,3,4 这种格式
    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 <T, S extends T>
    boolean
    addIfAbsent(Collection<T> collection, S object)
    一个对象不为空且不存在于该集合中时,加入到该集合中
    static <T> boolean
    allMatch(Collection<T> collection, Predicate<T> predicate)
    是否全部匹配判断条件
    static <T> boolean
    anyMatch(Collection<T> collection, Predicate<T> predicate)
    是否至少有一个符合判断条件
    static <E> Enumeration<E>
    Iterator转换为Enumeration Adapt the specified Iterator to the Enumeration interface.
    static void
    clear(Collection<?>... collections)
    清除一个或多个集合内的元素,每个集合调用clear()方法
    static boolean
    contains(Collection<?> collection, Object value)
    判断指定集合是否包含指定值,如果集合为空(null或者空),返回false,否则找到元素返回true
    static <T> boolean
    contains(Collection<T> collection, Predicate<? super T> containFunc)
    自定义函数判断集合是否包含某类值
    static boolean
    containsAll(Collection<?> coll1, Collection<?> coll2)
    集合1中是否包含集合2中所有的元素。 当集合1和集合2都为空时,返回true 当集合2为空时,返回true
    static boolean
    containsAny(Collection<?> coll1, Collection<?> coll2)
    其中一个集合在另一个集合中是否至少包含一个元素,即是两个集合是否至少有一个共同的元素
    static <T> int
    count(Iterable<T> iterable, Predicate<T> predicate)
    集合中匹配规则的数量
    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 <T> Collection<T>
    create(Class<?> collectionType, Class<T> elementType)
    创建新的集合对象,返回具体的泛型集合
    static <T> Collection<T>
    disjunction(Collection<T> coll1, Collection<T> coll2)
    两个集合的差集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留两个集合中此元素个数差的个数 例如:
    static <T> List<T>
    distinct(Collection<T> collection)
    去重集合
    static <T, K> List<T>
    distinct(Collection<T> collection, Function<T,K> key, boolean override)
    根据函数生成的KEY去重集合,如根据Bean的某个或者某些字段完成去重。 去重可选是保留最先加入的值还是后加入的值
    static <T> Predicate<T>
    distinct(Function<? super T,?> key)
    去重集合
    static <T extends Collection<E>, E>
    T
    edit(T collection, UnaryOperator<E> editor)
    编辑,此方法产生一个新集合 编辑过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
    static <E, T extends Collection<E>>
    T
    empty(Class<?> collectionClass)
    根据给定的集合类型,返回对应的空集合,支持类型包括:
    static <K, V> Map<K,V>
    fieldValueAsMap(Iterable<?> iterable, String fieldNameForKey, String fieldNameForValue)
    两个字段值组成新的Map
    static <K, V> Map<K,V>
    fieldValueMap(Iterable<V> iterable, String fieldName)
    字段值与列表值对应的Map,常用于元素对象中有唯一ID时需要按照这个ID查找对象的情况 例如:车牌号 = 车
    static <T extends Collection<E>, E>
    T
    filter(T collection, Predicate<E> predicate)
    过滤 过滤过程通过传入的Predicate实现来过滤返回需要的元素内容,可以实现以下功能:
    static <T> List<T>
    flat(Collection<?> collection)
    解构多层集合 例如:List<List<List<String>>> 解构成 List<String>
    static <T> List<T>
    flat(Collection<?> collection, boolean skipNull)
    解构多层集合 例如:List<List<List<String>>> 解构成 List<String> skipNull如果为true, 则解构后的集合里不包含null值,为false则会包含null值。
    static <T> void
    forEach(Iterable<T> iterable, BiConsumerX<T,Integer> consumer)
    循环遍历 Iterable,使用BiConsumerX 接受遍历的每条数据,并针对每条数据做处理
    static <T> void
    forEach(Enumeration<T> enumeration, BiConsumerX<T,Integer> consumer)
    循环遍历 Enumeration,使用BiConsumerX 接受遍历的每条数据,并针对每条数据做处理
    static <T> void
    forEach(Iterator<T> iterator, BiConsumerX<T,Integer> consumer)
    循环遍历 Iterator,使用BiConsumerX 接受遍历的每条数据,并针对每条数据做处理
    static <K, V> void
    forEach(Map<K,V> map, SerConsumer3<K,V,Integer> kvConsumer)
    循环遍历Map,使用SerConsumer3 接受遍历的每条数据,并针对每条数据做处理 和JDK8中的map.forEach不同的是,此方法支持index
    static <T> T
    get(Collection<T> collection, int index)
    获取集合中指定下标的元素值,下标可以为负数,例如-1表示最后一个元素 如果元素越界,返回null
    static <T> List<T>
    getAny(Collection<T> collection, int... indexes)
    获取集合中指定多个下标的元素值,下标可以为负数,例如-1表示最后一个元素
    getFieldValues(Iterable<?> collection, String fieldName)
    获取给定Bean列表中指定字段名对应字段值的列表 列表元素支持Bean与Map
    static List<Object>
    getFieldValues(Iterable<?> collection, String fieldName, boolean ignoreNull)
    获取给定Bean列表中指定字段名对应字段值的列表 列表元素支持Bean与Map
    static <T> List<T>
    getFieldValues(Iterable<?> collection, String fieldName, Class<T> elementType)
    获取给定Bean列表中指定字段名对应字段值的列表 列表元素支持Bean与Map
    static <T> T
    getFirst(Iterable<T> iterable)
    获取集合的第一个元素,如果集合为空(null或者空集合),返回null
    static <T> T
    getFirst(Iterable<T> collection, Predicate<T> predicate)
    查找第一个匹配元素对象
    static <T> T
    getFirstByField(Iterable<T> collection, String fieldName, Object fieldValue)
    查找第一个匹配元素对象 如果集合元素是Map,则比对键和值是否相同,相同则返回 如果为普通Bean,则通过反射比对元素字段名对应的字段值是否相同,相同则返回 如果给定字段值参数是null 且元素对象中的字段值也为null则认为相同
    static <T> T
    获取集合的第一个非空元素
    static <T> T
    getLast(Collection<T> collection)
    获取集合的最后一个元素
    static <T> List<List<T>>
    group(Collection<T> collection, Hash32<T> hash)
    分组,按照Hash32接口定义的hash算法,集合中的元素放入hash值对应的子列表中
    static <T> List<List<T>>
    groupByField(Collection<T> collection, String fieldName)
    根据元素的指定字段值分组,非Bean都放在第一个分组中
    static <T> List<List<T>>
    groupByFunc(Collection<T> collection, Function<T,?> getter)
    根据元素的指定字段值分组,非Bean都放在第一个分组中 例如: CollKit.groupByFunc(list, TestBean::getAge)
    static <T> List<Integer>
    indexListOfAll(Collection<T> collection, Predicate<T> predicate)
    获取匹配规则定义中匹配到元素的所有位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准。
    static <T> int
    indexOf(Collection<T> collection, Predicate<T> predicate)
    获取匹配规则定义中匹配到元素的第一个位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准。
    static <T> int[]
    indexOfAll(Collection<T> collection, Predicate<T> predicate)
    获取匹配规则定义中匹配到元素的所有位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准。
    static <T> Collection<T>
    intersection(Collection<T>... colls)
    多个集合的交集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最少的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c],此结果中只保留了两个c
    static <T> Set<T>
    多个集合的交集 针对一个集合中存在多个相同元素的情况,只保留一个 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c],此结果中只保留了一个c
    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 <K> Set<K>
    keySet(Collection<Map<K,?>> mapCollection)
    获取指定Map列表中所有的Key
    static <T> int
    lastIndexOf(Collection<T> collection, Predicate<? super T> predicate)
    获取匹配规则定义中匹配到元素的最后位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准。
    static <T, R> List<R>
    map(Iterable<T> collection, Function<? super T,? extends R> func)
    通过func自定义一个规则,此规则将原集合中的元素转换成新的元素,生成新的列表返回 例如提供的是一个Bean列表,通过Function接口实现获取某个字段值,返回这个字段值组成的新列表 默认忽略映射后null的情况
    static <T, R> List<R>
    map(Iterable<T> collection, Function<? super T,? extends R> mapper, boolean ignoreNull)
    通过func自定义一个规则,此规则将原集合中的元素转换成新的元素,生成新的列表返回 例如提供的是一个Bean列表,通过Function接口实现获取某个字段值,返回这个字段值组成的新列表
    static <T extends Comparable<? super T>>
    T
    max(Collection<T> coll)
    取最大值
    static <T extends Comparable<? super T>>
    T
    min(Collection<T> coll)
    取最小值
    static <T> BlockingQueue<T>
    newBlockingQueue(int capacity, boolean isLinked)
    新建BlockingQueue 在队列为空时,获取元素的线程会等待队列变为非空。当队列满时,存储元素的线程会等待队列可用。
    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<List<T>>
    partition(Collection<T> collection, int size)
    对集合按照指定长度分段,每一个段为单独的集合,返回这个集合的列表
    static <T> List<T>
    popPart(Deque<T> surplusAlaDatas, int partSize)
    切取部分数据 切取后的栈将减少这些元素
    static <T> List<T>
    popPart(Stack<T> surplusAlaDatas, int partSize)
    切取部分数据 切取后的栈将减少这些元素
    static <T extends Iterable<E>, E>
    T
    remove(T iter, Predicate<E> predicate)
    移除集合中满足条件的所有元素,此方法在原集合上直接修改 通过实现Predicate接口,完成元素的移除,可以实现以下功能:
    static <T extends Collection<E>, E>
    T
    removeAny(T collection, E... elesRemoved)
    去掉集合中的多个元素,此方法直接修改原集合
    static <T extends Collection<E>, E extends CharSequence>
    T
    removeBlank(T collection)
    去除null或者""或者空白字符串 元素,此方法直接修改原集合
    static <T extends Collection<E>, E extends CharSequence>
    T
    removeEmpty(T collection)
    去除null或者"" 元素,此方法直接修改原集合
    static <T extends Collection<E>, E>
    T
    removeNull(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 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 <E, K, V> void
    setValueByMap(Iterable<E> iterable, Map<K,V> map, Function<E,K> keyGenerate, BiConsumer<E,V> biConsumer)
    使用给定的map将集合中的元素进行属性或者值的重新设定
    static <T> List<T>
    sort(Collection<T> collection, Comparator<? super T> comparator)
    排序集合,排序不会修改原集合
    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 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 <K, V> LinkedHashMap<K,V>
    sortToMap(Collection<Map.Entry<K,V>> entryCollection, Comparator<Map.Entry<K,V>> comparator)
    通过Entry排序,可以按照键排序,也可以按照值排序,亦或者两者综合排序
    static <T> List<T>
    sub(Collection<T> collection, int start, int end)
    截取集合的部分
    static <T> List<T>
    sub(Collection<T> collection, 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)
    截取列表的部分
    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 <E> Collection<E>
    toCollection(Iterable<E> iterable)
    Iterable转为Collection 首先尝试强转,强转失败则构建一个新的ArrayList
    static <K, V> Map<K,List<V>>
    toListMap(Iterable<? extends Map<K,V>> mapList)
    行转列,合并相同的键,值合并为列表 将Map列表中相同key的值组成列表做为Map的value 是toMapList(Map)的逆方法 比如传入数据:
    static <K, V> List<Map<K,V>>
    toMapList(Map<K,? extends Iterable<V>> listMap)
    列转行。将Map中值列表分别按照其位置与key组成新的map。 是toListMap(Iterable)的逆方法 比如传入数据:
    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 <T> Collection<T>
    union(Collection<? extends T>... colls)
    多个集合的并集 针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最多的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c],此结果中只保留了三个c
    static <T> List<T>
    unionAll(Collection<? extends T>... colls)
    多个集合的完全并集,类似于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<? extends T>... colls)
    多个集合的非重复并集,类似于SQL中的“UNION DISTINCT” 针对一个集合中存在多个相同元素的情况,只保留一个 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c],此结果中只保留了一个c
    static <V> List<V>
    values(Collection<Map<?,V>> mapCollection)
    获取指定Map列表中所有的Value
    static <T> Collection<T>
    view(Collection<? extends T> c)
    转为只读集合
    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

    • distinct

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

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

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

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

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

      @SafeVarargs public static <T> List<T> unionAll(Collection<? extends T>... colls)
      多个集合的完全并集,类似于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:
      colls - 集合数组
      Returns:
      并集的集合,返回 ArrayList
    • intersection

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

      @SafeVarargs public static <T> Set<T> intersectionDistinct(Collection<T>... colls)
      多个集合的交集 针对一个集合中存在多个相同元素的情况,只保留一个 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c],此结果中只保留了一个c
      Type Parameters:
      T - 集合元素类型
      Parameters:
      colls - 集合列表
      Returns:
      交集的集合,返回 LinkedHashSet
    • disjunction

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

      public static boolean contains(Collection<?> collection, Object value)
      判断指定集合是否包含指定值,如果集合为空(null或者空),返回false,否则找到元素返回true
      Parameters:
      collection - 集合
      value - 需要查找的值
      Returns:
      如果集合为空(null或者空),返回false,否则找到元素返回true
      Throws:
      ClassCastException - 如果类型不一致会抛出转换异常
      NullPointerException - 当指定的元素 值为 null ,或集合类不支持null 时抛出该异常
      See Also:
    • safeContains

      public static boolean safeContains(Collection<?> collection, Object value)
      判断指定集合是否包含指定值,如果集合为空(null或者空),返回false,否则找到元素返回true
      Parameters:
      collection - 集合
      value - 需要查找的值
      Returns:
      果集合为空(null或者空),返回false,否则找到元素返回true
    • 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:
      两个集合是否至少有一个共同的元素
      See Also:
    • containsAll

      public static boolean containsAll(Collection<?> coll1, Collection<?> coll2)
      集合1中是否包含集合2中所有的元素。 当集合1和集合2都为空时,返回true 当集合2为空时,返回true
      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:
      连接后的字符串
      See Also:
    • 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(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
    • newBlockingQueue

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

      public static <E, T extends Collection<E>> T empty(Class<?> collectionClass)
      根据给定的集合类型,返回对应的空集合,支持类型包括:
           1. NavigableSet
           2. SortedSet
           3. Set
           4. List
       
      Type Parameters:
      E - 元素类型
      T - 集合类型
      Parameters:
      collectionClass - 集合类型
      Returns:
      空集合
    • create

      public static <T> Collection<T> create(Class<?> collectionType)
      创建新的集合对象,返回具体的泛型集合
      Type Parameters:
      T - 集合元素类型,rawtype 如 ArrayList.class, EnumMap.class ...
      Parameters:
      collectionType - 集合类型
      Returns:
      集合类型对应的实例
    • create

      public static <T> Collection<T> create(Class<?> collectionType, Class<T> elementType)
      创建新的集合对象,返回具体的泛型集合
      Type Parameters:
      T - 集合元素类型,rawtype 如 ArrayList.class, EnumMap.class ...
      Parameters:
      collectionType - 集合类型
      elementType - 集合元素类,只用于EnumSet创建,如果创建EnumSet,则此参数必须非空
      Returns:
      集合类型对应的实例
    • sub

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

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

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

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

      public static <T extends Collection<E>, E> T filter(T collection, Predicate<E> predicate)
      过滤 过滤过程通过传入的Predicate实现来过滤返回需要的元素内容,可以实现以下功能:
       1、过滤出需要的对象,Predicate.test(Object)方法返回true的对象将被加入结果集合中
       
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      collection - 集合
      predicate - 过滤器,null返回原集合
      Returns:
      过滤后的数组
    • removeAny

      public static <T extends Collection<E>, E> T removeAny(T collection, E... elesRemoved)
      去掉集合中的多个元素,此方法直接修改原集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      collection - 集合
      elesRemoved - 需要删除的元素
      Returns:
      原集合
    • remove

      public static <T extends Iterable<E>, E> T remove(T iter, Predicate<E> predicate)
      移除集合中满足条件的所有元素,此方法在原集合上直接修改 通过实现Predicate接口,完成元素的移除,可以实现以下功能:
       1、移除指定对象,Predicate.test(Object)方法返回
       true
       的对象将被使用Iterator.remove()方法移除。
       
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      iter - 集合
      predicate - 过滤器接口
      Returns:
      编辑后的集合
    • removeNull

      public static <T extends Collection<E>, E> T removeNull(T collection)
      去除null 元素,此方法直接修改原集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      处理后的集合
    • removeEmpty

      public static <T extends Collection<E>, E extends CharSequence> T removeEmpty(T collection)
      去除null或者"" 元素,此方法直接修改原集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      Parameters:
      collection - 集合
      Returns:
      处理后的集合
    • removeBlank

      public static <T extends Collection<E>, E extends CharSequence> T removeBlank(T collection)
      去除null或者""或者空白字符串 元素,此方法直接修改原集合
      Type Parameters:
      T - 集合类型
      E - 集合元素类型
      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:
      targetCollection - 被操作移除元素的集合
      resultCollection - 存放移除结果的集合
      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:
      移除结果的集合
    • map

      public static <T, R> List<R> map(Iterable<T> collection, Function<? super T,? extends R> func)
      通过func自定义一个规则,此规则将原集合中的元素转换成新的元素,生成新的列表返回 例如提供的是一个Bean列表,通过Function接口实现获取某个字段值,返回这个字段值组成的新列表 默认忽略映射后null的情况
      Type Parameters:
      T - 集合元素类型
      R - 返回集合元素类型
      Parameters:
      collection - 原集合
      func - 编辑函数
      Returns:
      抽取后的新列表
    • map

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

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

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

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

      public static <K, V> Map<K,V> fieldValueMap(Iterable<V> iterable, String fieldName)
      字段值与列表值对应的Map,常用于元素对象中有唯一ID时需要按照这个ID查找对象的情况 例如:车牌号 = 车
      Type Parameters:
      K - 字段名对应值得类型,不确定请使用Object
      V - 对象类型
      Parameters:
      iterable - 对象列表
      fieldName - 字段名(会通过反射获取其值)
      Returns:
      某个字段值与对象对应Map
    • fieldValueAsMap

      public static <K, V> Map<K,V> fieldValueAsMap(Iterable<?> iterable, String fieldNameForKey, String fieldNameForValue)
      两个字段值组成新的Map
      Type Parameters:
      K - 字段名对应值得类型,不确定请使用Object
      V - 值类型,不确定使用Object
      Parameters:
      iterable - 对象列表
      fieldNameForKey - 做为键的字段名(会通过反射获取其值)
      fieldNameForValue - 做为值的字段名(会通过反射获取其值)
      Returns:
      某个字段值与对象对应Map
    • getFirst

      public static <T> T getFirst(Iterable<T> iterable)
      获取集合的第一个元素,如果集合为空(null或者空集合),返回null
      Type Parameters:
      T - 集合元素类型
      Parameters:
      iterable - Iterable
      Returns:
      第一个元素,为空返回null
    • getFirstNoneNull

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

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

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

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

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

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

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

      public static <T> List<Integer> indexListOfAll(Collection<T> collection, Predicate<T> predicate)
      获取匹配规则定义中匹配到元素的所有位置 此方法对于某些无序集合的位置信息,以转换为数组后的位置为准。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      predicate - 匹配器,为空则全部匹配
      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
    • 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
    • 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)
      将指定对象全部加入到集合中 提供的对象如果为集合类型,会自动转换为目标元素类型 如果为String,支持类似于[1,2,3,4] 或者 1,2,3,4 这种格式
      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:
      原集合
    • getLast

      public static <T> T getLast(Collection<T> collection)
      获取集合的最后一个元素
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - Collection
      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:
      元素值列表
    • 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:
    • 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(Collection<String> collection)
      根据汉字的拼音顺序排序
      Parameters:
      collection - 集合,会被转换为List
      Returns:
      排序后的List
    • sortByPinyin

      public static List<String> sortByPinyin(List<String> list)
      根据汉字的拼音顺序排序
      Parameters:
      list - List
      Returns:
      排序后的List
    • 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
    • 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
    • forEach

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

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

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

      public static <K, V> void forEach(Map<K,V> map, SerConsumer3<K,V,Integer> kvConsumer)
      循环遍历Map,使用SerConsumer3 接受遍历的每条数据,并针对每条数据做处理 和JDK8中的map.forEach不同的是,此方法支持index
      Type Parameters:
      K - Key类型
      V - Value类型
      Parameters:
      map - Map
      kvConsumer - SerConsumer3 遍历的每条数据处理器
    • group

      public static <T> List<List<T>> group(Collection<T> collection, Hash32<T> hash)
      分组,按照Hash32接口定义的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:
      分组列表
    • groupByFunc

      public static <T> List<List<T>> groupByFunc(Collection<T> collection, Function<T,?> getter)
      根据元素的指定字段值分组,非Bean都放在第一个分组中 例如: CollKit.groupByFunc(list, TestBean::getAge)
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 集合
      getter - getter方法引用
      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:
    • view

      public static <T> Collection<T> view(Collection<? extends T> c)
      转为只读集合
      Type Parameters:
      T - 元素类型
      Parameters:
      c - 集合
      Returns:
      只读集合
    • 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:
      新类型的集合
    • setValueByMap

      public static <E, K, V> void setValueByMap(Iterable<E> iterable, Map<K,V> map, Function<E,K> keyGenerate, BiConsumer<E,V> biConsumer)
      使用给定的map将集合中的元素进行属性或者值的重新设定
      Type Parameters:
      E - 元素类型
      K - 替换的键
      V - 替换的值
      Parameters:
      iterable - 集合
      map - 映射集
      keyGenerate - 映射键生成函数
      biConsumer - 封装映射到的值函数 nick_wys
    • addIfAbsent

      public static <T, S extends T> boolean addIfAbsent(Collection<T> collection, S object)
      一个对象不为空且不存在于该集合中时,加入到该集合中
           null, null -> false
           [], null -> false
           null, "123" -> false
           ["123"], "123" -> false
           [], "123" -> true
           ["456"], "123" -> true
           [Animal{"name": "jack"}], Dog{"name": "jack"} -> true
       
      Type Parameters:
      T - 集合元素类型
      S - 要添加的元素类型【为集合元素类型的类型或子类型】
      Parameters:
      collection - 被加入的集合
      object - 要添加到集合的对象
      Returns:
      是否添加成功 Cloud-Style
    • anyMatch

      public static <T> boolean anyMatch(Collection<T> collection, Predicate<T> predicate)
      是否至少有一个符合判断条件
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      predicate - 自定义判断函数
      Returns:
      是否有一个值匹配 布尔值
    • allMatch

      public static <T> boolean allMatch(Collection<T> collection, Predicate<T> predicate)
      是否全部匹配判断条件
      Type Parameters:
      T - 集合元素类型
      Parameters:
      collection - 集合
      predicate - 自定义判断函数
      Returns:
      是否全部匹配 布尔值
    • flat

      public static <T> List<T> flat(Collection<?> collection)
      解构多层集合 例如:List<List<List<String>>> 解构成 List<String>
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 需要解构的集合
      Returns:
      解构后的集合
    • flat

      public static <T> List<T> flat(Collection<?> collection, boolean skipNull)
      解构多层集合 例如:List<List<List<String>>> 解构成 List<String> skipNull如果为true, 则解构后的集合里不包含null值,为false则会包含null值。
      Type Parameters:
      T - 元素类型
      Parameters:
      collection - 需要结构的集合
      skipNull - 是否跳过空的值
      Returns:
      解构后的集合
    • ringNextIntByObject

      public static int ringNextIntByObject(Object object, AtomicInteger atomicInteger)
      通过cas操作 实现对指定值内的回环累加
      Parameters:
      object - 集合
      • 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
      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:
      索引位置