java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
net.i2p.util.ArraySet<E>
net.i2p.util.UnmodifiableSortedSet<E>
- Type Parameters:
E- type of elements in this set
- All Implemented Interfaces:
Iterable<E>, Collection<E>, SequencedCollection<E>, SequencedSet<E>, Set<E>, SortedSet<E>
Efficient implementation of a SortedSet stored in a fixed-size array. Much more space-efficient than TreeSet. Doesn't do copying like CopyOnWriteArraySet. Unmodifiable, thread-safe. Null elements are not permitted.
The Collection constructors are not recommended for large sets as duplicate check is O(n**2).
Nested Class Summary
Nested classes/interfaces inherited from class ArraySet
ArraySet.SetFullExceptionModifier and TypeClassDescriptionstatic classException thrown when attempting to add an element to a full ArraySet.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Comparator<? super E> The order the set is kept in.private final booleanTrue once the set being wrapped has been suppliedFields inherited from class ArraySet
_entries, MAX_CAPACITYModifier and TypeFieldDescriptionprotected final Object[]The underlying array of entries.static final intThe maximum capacity for this set.Constructor Summary
ConstructorsConstructorDescriptionUnmodifiableSortedSet(Collection<? extends E> c) Warning: O(n**2).UnmodifiableSortedSet(Collection<? extends E> c, Comparator<? super E> comparator) Warning: O(n**2).UnmodifiableSortedSet(Set<? extends E> c) Copy of the given set, sorted.UnmodifiableSortedSet(Set<? extends E> c, Comparator<? super E> comparator) Copy of the given set, sorted with the given comparator.UnmodifiableSortedSet(SortedSet<? extends E> c) Copy of the given sorted set.UnmodifiableSortedSet(SortedSet<? extends E> c, Comparator<? super E> comparator) Copy of the given sorted set with the given comparator.Method Summary
Public MethodsModifier and TypeMethodDescriptionbooleanThrows, the set is unmodifiable.voidThrows, the set is unmodifiable.voidclear()Throws, the set is unmodifiable.Comparator<? super E> Comparator used for ordering, or null.first()First (lowest) element.Throws, the set is unmodifiable.protected intOverridden to do binary search.last()Last (highest) element.booleanThrows, the set is unmodifiable.Throws, the set is unmodifiable.Throws, the set is unmodifiable.Methods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface SortedSet
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed, spliterator
Field Details
comp
The order the set is kept in.initialized
private final boolean initializedTrue once the set being wrapped has been supplied
Constructor Details
UnmodifiableSortedSet
UnmodifiableSortedSet
Copy of the given sorted set with the given comparator.- Parameters:
c- sorted set to copy, must already be sortedcomparator- comparator for ordering
UnmodifiableSortedSet
UnmodifiableSortedSet
Copy of the given set, sorted with the given comparator.- Parameters:
c- set to copy and sortcomparator- comparator for ordering
UnmodifiableSortedSet
Warning: O(n**2).- Parameters:
c- collection to copy and sort
UnmodifiableSortedSet
Warning: O(n**2).- Parameters:
c- collection to copy and sortcomparator- comparator for ordering
Method Details
comparator
Comparator used for ordering, or null.- Specified by:
comparatorin interfaceSortedSet<E>
first
last
headSet
subSet
tailSet
add
Throws, the set is unmodifiable.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classArraySet<E>- Parameters:
o- the element to add- Throws:
UnsupportedOperationException- if the set has finished initializing; before that the call is allowed so the Collection constructor can populate it
addUnique
Throws, the set is unmodifiable.- Overrides:
addUniquein classArraySet<E>- Parameters:
o- non-null, NPE will not be thrown- Throws:
UnsupportedOperationException- if the set has finished initializing; before that the call is allowed so the Collection constructor can populate it
clear
public void clear()Throws, the set is unmodifiable.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classArraySet<E>- Throws:
UnsupportedOperationException- always, as the set cannot be emptied
remove
indexOf