Class LinkedHashMultiset<E>
java.lang.Object
java.util.AbstractCollection<E>
cloud.opencode.base.collections.specialized.AbstractMultiset<E>
cloud.opencode.base.collections.specialized.LinkedHashMultiset<E>
- Type Parameters:
E- element type | 元素类型
- All Implemented Interfaces:
Multiset<E>, Serializable, Iterable<E>, Collection<E>
LinkedHashMultiset - Linked Hash Multiset Implementation
LinkedHashMultiset - 链式哈希多重集合实现
A multiset that maintains insertion order of elements.
保持元素插入顺序的多重集合。
Features | 主要功能:
- Insertion order preservation - 保持插入顺序
- O(1) operations - O(1) 操作
- Predictable iteration order - 可预测的迭代顺序
Usage Examples | 使用示例:
LinkedHashMultiset<String> multiset = LinkedHashMultiset.create();
multiset.add("cherry", 3);
multiset.add("apple", 2);
multiset.add("banana");
// Iteration in insertion order - 按插入顺序迭代
for (String element : multiset.elementSet()) {
System.out.println(element + ": " + multiset.count(element));
}
// Output: cherry: 3, apple: 2, banana: 1
Performance | 性能特性:
- add: O(1) - add: O(1)
- remove: O(1) - remove: O(1)
- count: O(1) - count: O(1)
- contains: O(1) - contains: O(1)
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: No (nulls not allowed) - 空值安全: 否(不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Multiset
Multiset.Entry<E> -
Method Summary
Modifier and TypeMethodDescriptionintAdd a number of occurrences of an element.voidclear()booleanCheck if multiset contains the element.intReturn the count of the specified element.static <E> LinkedHashMultiset<E> create()Create an empty LinkedHashMultiset.static <E> LinkedHashMultiset<E> create(int expectedDistinctElements) Create a LinkedHashMultiset with expected size.static <E> LinkedHashMultiset<E> Create a LinkedHashMultiset from elements.Return the set of distinct elements.entrySet()Return the set of entries (element with count).booleanisEmpty()iterator()intRemove a number of occurrences of an element.intSet the count of an element.booleanConditionally set the count of an element.intsize()Return the total count of all elements.Methods inherited from class AbstractMultiset
add, addAll, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Method Details
-
create
Create an empty LinkedHashMultiset. 创建空 LinkedHashMultiset。- Type Parameters:
E- element type | 元素类型- Returns:
- new empty LinkedHashMultiset | 新空 LinkedHashMultiset
-
create
Create a LinkedHashMultiset with expected size. 创建指定预期大小的 LinkedHashMultiset。- Type Parameters:
E- element type | 元素类型- Parameters:
expectedDistinctElements- expected number of distinct elements | 预期不同元素数量- Returns:
- new empty LinkedHashMultiset | 新空 LinkedHashMultiset
-
create
Create a LinkedHashMultiset from elements. 从元素创建 LinkedHashMultiset。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素- Returns:
- new LinkedHashMultiset | 新 LinkedHashMultiset
-
count
-
add
Description copied from interface:MultisetAdd a number of occurrences of an element. 添加元素的多个出现。 -
remove
Description copied from interface:MultisetRemove a number of occurrences of an element. 移除元素的多个出现。 -
setCount
-
setCount
Description copied from interface:MultisetConditionally set the count of an element. 条件性地设置元素的计数。 -
elementSet
-
entrySet
-
size
public int size()Description copied from interface:MultisetReturn the total count of all elements. 返回所有元素的总计数。- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceMultiset<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- total size | 总大小
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
Description copied from interface:MultisetCheck if multiset contains the element. 检查多重集是否包含元素。- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceMultiset<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
o- the element | 元素- Returns:
- true if contains | 如果包含则返回 true
-
iterator
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>
-