Class CollectionFactory
java.lang.Object
cloud.opencode.base.collections.CollectionFactory
CollectionFactory - Factory for Creating Collections
CollectionFactory - 创建集合的工厂
Provides factory methods for creating various collection types with consistent API across different implementations.
提供创建各种集合类型的工厂方法,跨不同实现提供一致的 API。
Features | 主要功能:
- List factories - 列表工厂
- Set factories - 集合工厂
- Map factories - 映射工厂
- Queue and Deque factories - 队列和双端队列工厂
- Concurrent collection factories - 并发集合工厂
Usage Examples | 使用示例:
// Create lists - 创建列表
List<String> arrayList = CollectionFactory.newArrayList();
List<String> linkedList = CollectionFactory.newLinkedList();
// Create sets - 创建集合
Set<String> hashSet = CollectionFactory.newHashSet();
Set<String> linkedHashSet = CollectionFactory.newLinkedHashSet();
Set<String> treeSet = CollectionFactory.newTreeSet();
// Create maps - 创建映射
Map<String, Integer> hashMap = CollectionFactory.newHashMap();
Map<String, Integer> linkedHashMap = CollectionFactory.newLinkedHashMap();
Map<String, Integer> treeMap = CollectionFactory.newTreeMap();
// Create concurrent collections - 创建并发集合
Map<String, Integer> concurrentMap = CollectionFactory.newConcurrentHashMap();
Set<String> concurrentSet = CollectionFactory.newConcurrentHashSet();
Security | 安全性:
- Thread-safe: Yes (stateless factory) - 线程安全: 是(无状态工厂)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity) Create an ArrayBlockingQueue.static <E> ArrayDeque<E> Create an ArrayDeque.static <E> ArrayList<E> Create an ArrayList.static <E> ArrayList<E> newArrayList(E... elements) Create an ArrayList with initial elements.static <E> ArrayList<E> newArrayList(Iterable<? extends E> elements) Create an ArrayList from an iterable.static <E> ArrayList<E> newArrayListWithCapacity(int initialCapacity) Create an ArrayList with initial capacity.static <K,V> ConcurrentHashMap <K, V> Create a ConcurrentHashMap.static <E> Set<E> Create a concurrent hash set.static <E> ConcurrentLinkedDeque<E> Create a ConcurrentLinkedDeque.static <E> ConcurrentLinkedQueue<E> Create a ConcurrentLinkedQueue.static <K extends Comparable<? super K>, V>
ConcurrentSkipListMap<K, V> Create a ConcurrentSkipListMap.static <E> CopyOnWriteArrayList<E> Create a CopyOnWriteArrayList.static <E> CopyOnWriteArraySet<E> Create a CopyOnWriteArraySet.newEnumMap(Class<K> keyType) Create an EnumMap.newEnumSet(E first, E... elements) Create an EnumSet from elements.static <K,V> HashMap <K, V> Create a HashMap.static <K,V> HashMap <K, V> newHashMapWithCapacity(int initialCapacity) Create a HashMap with initial capacity.static <E> HashSet<E> Create a HashSet.static <E> HashSet<E> newHashSet(E... elements) Create a HashSet with initial elements.static <E> HashSet<E> newHashSet(Iterable<? extends E> elements) Create a HashSet from an iterable.static <K,V> IdentityHashMap <K, V> Create an IdentityHashMap.static <E> LinkedBlockingQueue<E> Create a LinkedBlockingQueue.static <K,V> LinkedHashMap <K, V> Create a LinkedHashMap.static <E> LinkedHashSet<E> Create a LinkedHashSet.static <E> LinkedHashSet<E> newLinkedHashSet(E... elements) Create a LinkedHashSet with initial elements.static <E> LinkedList<E> Create a LinkedList.static <E> LinkedList<E> newLinkedList(Iterable<? extends E> elements) Create a LinkedList from an iterable.static <E extends Comparable<? super E>>
PriorityBlockingQueue<E> Create a PriorityBlockingQueue.static <E extends Comparable<? super E>>
PriorityQueue<E> Create a PriorityQueue.static <E> PriorityQueue<E> newPriorityQueue(Comparator<? super E> comparator) Create a PriorityQueue with a comparator.static <K extends Comparable<? super K>, V>
TreeMap<K, V> Create a TreeMap.static <K,V> TreeMap <K, V> newTreeMap(Comparator<? super K> comparator) Create a TreeMap with a comparator.static <E extends Comparable<? super E>>
TreeSet<E> Create a TreeSet.static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator) Create a TreeSet with a comparator.static <K,V> WeakHashMap <K, V> Create a WeakHashMap.
-
Method Details
-
newArrayList
Create an ArrayList. 创建 ArrayList。- Type Parameters:
E- element type | 元素类型- Returns:
- new ArrayList | 新的 ArrayList
-
newArrayList
Create an ArrayList with initial elements. 创建带初始元素的 ArrayList。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- initial elements | 初始元素- Returns:
- new ArrayList | 新的 ArrayList
-
newArrayList
-
newArrayListWithCapacity
Create an ArrayList with initial capacity. 创建指定容量的 ArrayList。- Type Parameters:
E- element type | 元素类型- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new ArrayList | 新的 ArrayList
-
newLinkedList
Create a LinkedList. 创建 LinkedList。- Type Parameters:
E- element type | 元素类型- Returns:
- new LinkedList | 新的 LinkedList
-
newLinkedList
Create a LinkedList from an iterable. 从可迭代对象创建 LinkedList。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- elements | 元素- Returns:
- new LinkedList | 新的 LinkedList
-
newCopyOnWriteArrayList
Create a CopyOnWriteArrayList. 创建 CopyOnWriteArrayList。- Type Parameters:
E- element type | 元素类型- Returns:
- new CopyOnWriteArrayList | 新的 CopyOnWriteArrayList
-
newHashSet
Create a HashSet. 创建 HashSet。- Type Parameters:
E- element type | 元素类型- Returns:
- new HashSet | 新的 HashSet
-
newHashSet
Create a HashSet with initial elements. 创建带初始元素的 HashSet。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- initial elements | 初始元素- Returns:
- new HashSet | 新的 HashSet
-
newHashSet
-
newLinkedHashSet
Create a LinkedHashSet. 创建 LinkedHashSet。- Type Parameters:
E- element type | 元素类型- Returns:
- new LinkedHashSet | 新的 LinkedHashSet
-
newLinkedHashSet
Create a LinkedHashSet with initial elements. 创建带初始元素的 LinkedHashSet。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- initial elements | 初始元素- Returns:
- new LinkedHashSet | 新的 LinkedHashSet
-
newTreeSet
Create a TreeSet. 创建 TreeSet。- Type Parameters:
E- element type | 元素类型- Returns:
- new TreeSet | 新的 TreeSet
-
newTreeSet
Create a TreeSet with a comparator. 创建带比较器的 TreeSet。- Type Parameters:
E- element type | 元素类型- Parameters:
comparator- the comparator | 比较器- Returns:
- new TreeSet | 新的 TreeSet
-
newEnumSet
Create an EnumSet from elements. 从元素创建 EnumSet。- Type Parameters:
E- enum type | 枚举类型- Parameters:
first- first element | 第一个元素elements- additional elements | 附加元素- Returns:
- new EnumSet | 新的 EnumSet
-
newConcurrentHashSet
Create a concurrent hash set. 创建并发哈希集合。- Type Parameters:
E- element type | 元素类型- Returns:
- new concurrent set | 新的并发集合
-
newCopyOnWriteArraySet
Create a CopyOnWriteArraySet. 创建 CopyOnWriteArraySet。- Type Parameters:
E- element type | 元素类型- Returns:
- new CopyOnWriteArraySet | 新的 CopyOnWriteArraySet
-
newHashMap
Create a HashMap. 创建 HashMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new HashMap | 新的 HashMap
-
newHashMapWithCapacity
Create a HashMap with initial capacity. 创建指定容量的 HashMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new HashMap | 新的 HashMap
-
newLinkedHashMap
Create a LinkedHashMap. 创建 LinkedHashMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new LinkedHashMap | 新的 LinkedHashMap
-
newTreeMap
Create a TreeMap. 创建 TreeMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new TreeMap | 新的 TreeMap
-
newTreeMap
Create a TreeMap with a comparator. 创建带比较器的 TreeMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
comparator- the comparator | 比较器- Returns:
- new TreeMap | 新的 TreeMap
-
newEnumMap
-
newConcurrentHashMap
Create a ConcurrentHashMap. 创建 ConcurrentHashMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new ConcurrentHashMap | 新的 ConcurrentHashMap
-
newConcurrentSkipListMap
public static <K extends Comparable<? super K>, V> ConcurrentSkipListMap<K,V> newConcurrentSkipListMap()Create a ConcurrentSkipListMap. 创建 ConcurrentSkipListMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new ConcurrentSkipListMap | 新的 ConcurrentSkipListMap
-
newIdentityHashMap
Create an IdentityHashMap. 创建 IdentityHashMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new IdentityHashMap | 新的 IdentityHashMap
-
newWeakHashMap
Create a WeakHashMap. 创建 WeakHashMap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new WeakHashMap | 新的 WeakHashMap
-
newArrayDeque
Create an ArrayDeque. 创建 ArrayDeque。- Type Parameters:
E- element type | 元素类型- Returns:
- new ArrayDeque | 新的 ArrayDeque
-
newPriorityQueue
Create a PriorityQueue. 创建 PriorityQueue。- Type Parameters:
E- element type | 元素类型- Returns:
- new PriorityQueue | 新的 PriorityQueue
-
newPriorityQueue
Create a PriorityQueue with a comparator. 创建带比较器的 PriorityQueue。- Type Parameters:
E- element type | 元素类型- Parameters:
comparator- the comparator | 比较器- Returns:
- new PriorityQueue | 新的 PriorityQueue
-
newLinkedBlockingQueue
Create a LinkedBlockingQueue. 创建 LinkedBlockingQueue。- Type Parameters:
E- element type | 元素类型- Returns:
- new LinkedBlockingQueue | 新的 LinkedBlockingQueue
-
newArrayBlockingQueue
Create an ArrayBlockingQueue. 创建 ArrayBlockingQueue。- Type Parameters:
E- element type | 元素类型- Parameters:
capacity- the capacity | 容量- Returns:
- new ArrayBlockingQueue | 新的 ArrayBlockingQueue
-
newPriorityBlockingQueue
Create a PriorityBlockingQueue. 创建 PriorityBlockingQueue。- Type Parameters:
E- element type | 元素类型- Returns:
- new PriorityBlockingQueue | 新的 PriorityBlockingQueue
-
newConcurrentLinkedQueue
Create a ConcurrentLinkedQueue. 创建 ConcurrentLinkedQueue。- Type Parameters:
E- element type | 元素类型- Returns:
- new ConcurrentLinkedQueue | 新的 ConcurrentLinkedQueue
-
newConcurrentLinkedDeque
Create a ConcurrentLinkedDeque. 创建 ConcurrentLinkedDeque。- Type Parameters:
E- element type | 元素类型- Returns:
- new ConcurrentLinkedDeque | 新的 ConcurrentLinkedDeque
-