Class SetKit

java.lang.Object
org.miaixz.bus.core.xyz.SetKit

public class SetKit extends Object
集合中的Set相关方法封装
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Set<T>
    获取一个空Set,这个空Set不可变
    static <T> HashSet<T>
    of(boolean isLinked)
    新建一个List 如果提供的初始化数组为空,新建默认初始长度的List
    static <T> HashSet<T>
    of(boolean isLinked, Iterable<T> iterable)
    新建一个HashSet 提供的参数为null时返回空HashSet
    static <T> HashSet<T>
    of(boolean isLinked, Enumeration<T> enumeration)
    新建一个HashSet
    static <T> HashSet<T>
    of(boolean isSorted, Iterator<T> iter)
    新建一个HashSet
    static <T> HashSet<T>
    of(Iterable<T> iterable)
    新建一个HashSet
    static <T> SetFromMap<T>
    of(Map<T,Boolean> map)
    新建一个SetFromMap
    static <T> HashSet<T>
    of(T... ts)
    新建一个HashSet
    static <T> LinkedHashSet<T>
    ofLinked(T... ts)
    新建一个LinkedHashSet
    static <T> Set<T>
    unmodifiable(Set<? extends T> c)
    转为只读Set
    static <T> Set<T>
    view(Set<T> ts)
    转为一个不可变Set
    static <T> Set<T>
    view(T... ts)
    数组转为一个不可变List 类似于Java9中的List.of
    static <T> Set<T>
    获取一个初始大小为0的Set,这个空Set可变
    static <T> Set<T>
    获取一个初始大小为0的LinkedHashSet,这个空Set可变

    Methods inherited from class java.lang.Object

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

    • SetKit

      public SetKit()
  • Method Details

    • of

      public static <T> HashSet<T> of(boolean isLinked)
      新建一个List 如果提供的初始化数组为空,新建默认初始长度的List
      Type Parameters:
      T - 集合元素类型
      Parameters:
      isLinked - 是否为链表
      Returns:
      List对象
    • of

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

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

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

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

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

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

      public static <T> SetFromMap<T> of(Map<T,Boolean> map)
      新建一个SetFromMap
      Type Parameters:
      T - 集合元素类型
      Parameters:
      map - Map
      Returns:
      SetFromMap对象
    • view

      @SafeVarargs public static <T> Set<T> view(T... ts)
      数组转为一个不可变List 类似于Java9中的List.of
      Type Parameters:
      T - 对象类型
      Parameters:
      ts - 对象
      Returns:
      不可修改List
    • view

      public static <T> Set<T> view(Set<T> ts)
      转为一个不可变Set
      Type Parameters:
      T - 对象类型
      Parameters:
      ts - 对象
      Returns:
      不可修改List,如果提供List为null或者空,返回Collections.emptySet()
    • empty

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

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

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

      public static <T> Set<T> unmodifiable(Set<? extends T> c)
      转为只读Set
      Type Parameters:
      T - 元素类型
      Parameters:
      c - 集合
      Returns:
      只读集合
      See Also: