Class ImmutableSortedSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
cloud.opencode.base.collections.immutable.ImmutableSortedSet<E>
- Type Parameters:
E- element type | 元素类型
- All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, NavigableSet<E>, SequencedCollection<E>, SequencedSet<E>, Set<E>, SortedSet<E>
public final class ImmutableSortedSet<E>
extends AbstractSet<E>
implements NavigableSet<E>, Serializable
ImmutableSortedSet - Immutable Sorted Set Implementation
ImmutableSortedSet - 不可变有序集合实现
A sorted set that cannot be modified after creation. Elements are stored in sorted order according to their natural ordering or a provided comparator.
创建后不能修改的有序集合。元素按自然顺序或提供的比较器排序存储。
Features | 主要功能:
- Immutable - 不可变
- Thread-safe - 线程安全
- Sorted elements - 元素有序
- NavigableSet operations - NavigableSet 操作
Usage Examples | 使用示例:
// Create from elements - 从元素创建
ImmutableSortedSet<String> set = ImmutableSortedSet.of("c", "a", "b");
// Result: [a, b, c]
// Create with comparator - 使用比较器创建
ImmutableSortedSet<String> set = ImmutableSortedSet.orderedBy(String.CASE_INSENSITIVE_ORDER)
.add("A", "b", "C")
.build();
Performance | 性能特性:
- contains: O(log n) - contains: O(log n)
- iteration: O(n) - iteration: O(n)
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Yes (nulls not allowed) - 空值安全: 是(不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ImmutableSortedSet. -
Method Summary
Modifier and TypeMethodDescriptionComparator<? super E> booleanstatic <E extends Comparable<? super E>>
ImmutableSortedSet<E> copyOf(Collection<? extends E> elements) Copy from a collection.static <E> ImmutableSortedSet<E> copyOf(Collection<? extends E> elements, Comparator<? super E> comparator) Copy from a collection with comparator.first()booleanisEmpty()iterator()last()static <E extends Comparable<? super E>>
ImmutableSortedSet.Builder<E> Create a builder with natural ordering.static <E extends Comparable<? super E>>
ImmutableSortedSet<E> of()Return an empty immutable sorted set.static <E extends Comparable<? super E>>
ImmutableSortedSet<E> of(E e1) Return an immutable sorted set with one element.static <E extends Comparable<? super E>>
ImmutableSortedSet<E> of(E... elements) Return an immutable sorted set with multiple elements.static <E> ImmutableSortedSet.Builder<E> orderedBy(Comparator<? super E> comparator) Create a builder with specified comparator.pollLast()intsize()Methods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
add, addAll, clear, containsAll, remove, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface NavigableSet
removeFirst, removeLast, reversed
-
Method Details
-
of
Return an empty immutable sorted set. 返回空不可变有序集合。- Type Parameters:
E- element type | 元素类型- Returns:
- empty immutable sorted set | 空不可变有序集合
-
of
Return an immutable sorted set with one element. 返回包含一个元素的不可变有序集合。- Type Parameters:
E- element type | 元素类型- Parameters:
e1- the element | 元素- Returns:
- immutable sorted set | 不可变有序集合
-
of
@SafeVarargs public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E... elements) Return an immutable sorted set with multiple elements. 返回包含多个元素的不可变有序集合。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素- Returns:
- immutable sorted set | 不可变有序集合
-
copyOf
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> copyOf(Collection<? extends E> elements) Copy from a collection. 从集合复制。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素- Returns:
- immutable sorted set | 不可变有序集合
-
copyOf
public static <E> ImmutableSortedSet<E> copyOf(Collection<? extends E> elements, Comparator<? super E> comparator) Copy from a collection with comparator. 使用比较器从集合复制。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素comparator- the comparator | 比较器- Returns:
- immutable sorted set | 不可变有序集合
-
naturalOrder
Create a builder with natural ordering. 创建使用自然顺序的构建器。- Type Parameters:
E- element type | 元素类型- Returns:
- builder | 构建器
-
orderedBy
Create a builder with specified comparator. 创建使用指定比较器的构建器。- Type Parameters:
E- element type | 元素类型- Parameters:
comparator- the comparator | 比较器- Returns:
- builder | 构建器
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
-
comparator
- Specified by:
comparatorin interfaceSortedSet<E>
-
first
-
last
-
lower
- Specified by:
lowerin interfaceNavigableSet<E>
-
floor
- Specified by:
floorin interfaceNavigableSet<E>
-
ceiling
- Specified by:
ceilingin interfaceNavigableSet<E>
-
higher
- Specified by:
higherin interfaceNavigableSet<E>
-
pollFirst
- Specified by:
pollFirstin interfaceNavigableSet<E>
-
pollLast
- Specified by:
pollLastin interfaceNavigableSet<E>
-
descendingSet
- Specified by:
descendingSetin interfaceNavigableSet<E>
-
descendingIterator
- Specified by:
descendingIteratorin interfaceNavigableSet<E>
-
subSet
public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) - Specified by:
subSetin interfaceNavigableSet<E>
-
headSet
- Specified by:
headSetin interfaceNavigableSet<E>
-
tailSet
- Specified by:
tailSetin interfaceNavigableSet<E>
-
subSet
-
headSet
-
tailSet
-