java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.jhotdraw8.icollection.MutableRedBlackSet<E>
- Type Parameters:
E- the element type
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,NavigableSet<E>,SequencedCollection<E>,SequencedSet<E>,Set<E>,SortedSet<E>,ReadOnlyCollection<E>,ReadOnlyNavigableSet<E>,ReadOnlySequencedCollection<E>,ReadOnlySequencedSet<E>,ReadOnlySet<E>,ReadOnlySortedSet<E>
public class MutableRedBlackSet<E>
extends AbstractSet<E>
implements NavigableSet<E>, Serializable, Cloneable, ReadOnlyNavigableSet<E>
Implements the
NavigableSet interface using a Red-Black tree.
References:
For a similar design, see 'TreeSet.java' in vavr. The internal data structure of this class is licensed from vavr.
- TreeSet.java. Copyright 2023 (c) vavr. MIT License.
- github.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of times this set has been structurally modified. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, empty set, sorted according to the natural ordering of its elements.MutableRedBlackSet(Iterable<? extends E> c) Constructs a new tree set containing the elements in the specified collection, sorted according to the natural ordering of its elements.MutableRedBlackSet(@Nullable Comparator<E> comparator) Constructs a new, empty set, sorted according to the specified comparator.MutableRedBlackSet(@Nullable Comparator<E> comparator, Collection<? extends E> c) Constructs a new tree set containing the elements in the specified collection, sorted according to the specified comparator. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanReturns the least element in this set greater than or equal to the given element, or null if there is no such element.voidclear()clone()@Nullable Comparator<? super E> Returns the comparator used to order the elements in this set, ornullif this set uses the natural ordering of its elements.booleanReturnstrueif this collection contains the specified object.first()Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.getFirst()Gets the first element.getLast()Gets the last element.protected intReturns the current value of the modification counter.Returns the least element in this set greater than the given element, or null if there is no such element.booleanisEmpty()Returns true if the collection is empty.iterator()Returns an iterator over the elements in this collection.last()Returns the greatest element in this set less than the given element, or null if there is no such element.pollLast()Returns a reversed-order view of this set.booleanintsize()Returns the size of the collection.stream()Returns a stream.Returns an immutable copy of this set.toString()Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, toArrayMethods inherited from interface java.util.NavigableSet
removeFirst, removeLast, reversedMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection
containsAll, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection
asCollectionMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedSet
asSetMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySet
characteristics, equals, hashCode
-
Field Details
-
modCount
protected transient int modCountThe number of times this set has been structurally modified.
-
-
Constructor Details
-
MutableRedBlackSet
Constructs a new, empty set, sorted according to the specified comparator.- Parameters:
comparator- a comparator, ifnullthe natural ordering of the elements is used
-
MutableRedBlackSet
Constructs a new tree set containing the elements in the specified collection, sorted according to the specified comparator.- Parameters:
comparator- a comparator, ifnullthe natural ordering of the elements is usedc- the collection
-
MutableRedBlackSet
public MutableRedBlackSet()Constructs a new, empty set, sorted according to the natural ordering of its elements. -
MutableRedBlackSet
Constructs a new tree set containing the elements in the specified collection, sorted according to the natural ordering of its elements.- Parameters:
c- the collection
-
-
Method Details
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
addAll
-
ceiling
Description copied from interface:ReadOnlyNavigableSetReturns the least element in this set greater than or equal to the given element, or null if there is no such element.- Specified by:
ceilingin interfaceNavigableSet<E>- Specified by:
ceilingin interfaceReadOnlyNavigableSet<E>- Parameters:
e- the given element- Returns:
- ceiling element or null
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
clone
-
comparator
Description copied from interface:ReadOnlySortedSetReturns the comparator used to order the elements in this set, ornullif this set uses the natural ordering of its elements.- Specified by:
comparatorin interfaceReadOnlySortedSet<E>- Specified by:
comparatorin interfaceSortedSet<E>- Returns:
- comparator or null
-
contains
Description copied from interface:ReadOnlyCollectionReturnstrueif this collection contains the specified object.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceReadOnlyCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
o- an object- Returns:
trueif this collection contains the specified object
-
descendingIterator
- Specified by:
descendingIteratorin interfaceNavigableSet<E>
-
descendingSet
- Specified by:
descendingSetin interfaceNavigableSet<E>
-
first
-
floor
Description copied from interface:ReadOnlyNavigableSetReturns the greatest element in this set less than or equal to the given element, or null if there is no such element.- Specified by:
floorin interfaceNavigableSet<E>- Specified by:
floorin interfaceReadOnlyNavigableSet<E>- Parameters:
e- the given element- Returns:
- floor element or null
-
getFirst
Description copied from interface:ReadOnlySequencedCollectionGets the first element.- Specified by:
getFirstin interfaceReadOnlySequencedCollection<E>- Specified by:
getFirstin interfaceSequencedCollection<E>- Specified by:
getFirstin interfaceSortedSet<E>- Returns:
- an element
-
getLast
Description copied from interface:ReadOnlySequencedCollectionGets the last element.- Specified by:
getLastin interfaceReadOnlySequencedCollection<E>- Specified by:
getLastin interfaceSequencedCollection<E>- Specified by:
getLastin interfaceSortedSet<E>- Returns:
- an element
-
getModCount
protected int getModCount()Returns the current value of the modification counter.- Returns:
- value of modification counter
-
headSet
- Specified by:
headSetin interfaceNavigableSet<E>
-
headSet
-
higher
Description copied from interface:ReadOnlyNavigableSetReturns the least element in this set greater than the given element, or null if there is no such element.- Specified by:
higherin interfaceNavigableSet<E>- Specified by:
higherin interfaceReadOnlyNavigableSet<E>- Parameters:
e- the given element- Returns:
- higher element or null
-
isEmpty
public boolean isEmpty()Description copied from interface:ReadOnlyCollectionReturns true if the collection is empty.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceReadOnlyCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
- true if empty
-
iterator
Description copied from interface:ReadOnlyCollectionReturns an iterator over the elements in this collection.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceNavigableSet<E>- Specified by:
iteratorin interfaceReadOnlyCollection<E>- Specified by:
iteratorin interfaceSet<E>- Specified by:
iteratorin classAbstractCollection<E>- Returns:
- an iterator
-
last
-
lower
Description copied from interface:ReadOnlyNavigableSetReturns the greatest element in this set less than the given element, or null if there is no such element.- Specified by:
lowerin interfaceNavigableSet<E>- Specified by:
lowerin interfaceReadOnlyNavigableSet<E>- Parameters:
e- the given element- Returns:
- lower element or null
-
pollFirst
- Specified by:
pollFirstin interfaceNavigableSet<E>
-
pollLast
- Specified by:
pollLastin interfaceNavigableSet<E>
-
readOnlyReversed
Description copied from interface:ReadOnlySequencedSetReturns a reversed-order view of this set. Changes to the underlying set are visible in the reversed view.- Specified by:
readOnlyReversedin interfaceReadOnlySequencedCollection<E>- Specified by:
readOnlyReversedin interfaceReadOnlySequencedSet<E>- Returns:
- a reversed-order view of this set
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
size
public int size()Description copied from interface:ReadOnlyCollectionReturns the size of the collection.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceReadOnlyCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- the size
-
spliterator
- Specified by:
spliteratorin interfaceCollection<E>- Specified by:
spliteratorin interfaceIterable<E>- Specified by:
spliteratorin interfaceSet<E>- Specified by:
spliteratorin interfaceSortedSet<E>
-
stream
Description copied from interface:ReadOnlyCollectionReturns a stream.- Specified by:
streamin interfaceCollection<E>- Specified by:
streamin interfaceReadOnlyCollection<E>- Returns:
- a stream
-
subSet
public @NonNull NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) - Specified by:
subSetin interfaceNavigableSet<E>
-
subSet
-
tailSet
- Specified by:
tailSetin interfaceNavigableSet<E>
-
tailSet
-
toImmutable
Returns an immutable copy of this set.- Returns:
- an immutable copy
-
toString
- Overrides:
toStringin classAbstractCollection<E>
-