Class SortedCopyOnWriteSet<E,C extends Comparable<C>>
java.lang.Object
com.comphenix.protocol.concurrent.SortedCopyOnWriteSet<E,C>
- Type Parameters:
E- the type of elements maintained by this setC- the type of the comparable used for ordering the elements
- All Implemented Interfaces:
Iterable<E>
A collection that stores elements in a sorted order based on a provided
Comparable, while ensuring element equality is checked using their
equals method.
This class uses a copy-on-write strategy for updates, ensuring that iteration over the collection is safe for concurrent use, even though the collection itself is not thread-safe for modifications.
Elements are inserted into the set in a position determined by their natural
ordering. If multiple elements have comparables that are considered equal
(i.e., compareTo returns zero), they will maintain their insertion
order. If an element is already present in the set (as determined by
equals), it will not be added again.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the specified element to this set in a sorted order based on the providedComparable.booleanisEmpty()Returnstrueif this set contains no elements.iterator()Returns an iterator over the elements in this set.booleanRemoves the specified element from this set if it is present.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SortedCopyOnWriteSet
public SortedCopyOnWriteSet()
-
-
Method Details
-
add
Adds the specified element to this set in a sorted order based on the providedComparable. The element will be inserted before the first position that is strictly greater than the element. This ensures that elements maintain their insertion order when their comparables are considered equal (i.e., whencompareToreturns zero).If the set already contains the element (as determined by
equals), the element is not added again.- Parameters:
element- the element to be addedcomparable- the comparable used to determine the element's position in the sorted order- Returns:
trueif the element was added to the set;falseif the set already contained the element- Throws:
NullPointerException- if the specified element is null
-
remove
Removes the specified element from this set if it is present.- Parameters:
element- the element to be removed- Returns:
trueif the set contained the specified element;falseotherwise- Throws:
NullPointerException- if the specified element is null
-
isEmpty
public boolean isEmpty()Returnstrueif this set contains no elements.- Returns:
trueif this set contains no elements
-
iterator
Returns an iterator over the elements in this set. The elements are returned in natural order.
-