Package net.i2p.util
Class UnmodifiableSortedSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- net.i2p.util.ArraySet<E>
-
- net.i2p.util.UnmodifiableSortedSet<E>
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
,SortedSet<E>
public class UnmodifiableSortedSet<E> extends ArraySet<E> implements 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 the duplicate check is O(n**2).- Since:
- 0.9.55
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.i2p.util.ArraySet
ArraySet.SetFullException
-
-
Field Summary
-
Fields inherited from class net.i2p.util.ArraySet
_entries, MAX_CAPACITY
-
-
Constructor Summary
Constructors Constructor Description UnmodifiableSortedSet(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)
UnmodifiableSortedSet(Set<? extends E> c, Comparator<? super E> comparator)
UnmodifiableSortedSet(SortedSet<? extends E> c)
UnmodifiableSortedSet(SortedSet<? extends E> c, Comparator<? super E> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E o)
void
addUnique(E o)
Unconditionally add o to the set.void
clear()
Comparator<? super E>
comparator()
E
first()
SortedSet<E>
headSet(E toElement)
protected int
indexOf(Object o)
Overridden to do binary searchE
last()
boolean
remove(Object o)
SortedSet<E>
subSet(E fromElement, E toElement)
SortedSet<E>
tailSet(E fromElement)
-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
addAll, contains, containsAll, equals, hashCode, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray
-
Methods inherited from interface java.util.SortedSet
spliterator
-
-
-
-
Constructor Detail
-
UnmodifiableSortedSet
public UnmodifiableSortedSet(SortedSet<? extends E> c, Comparator<? super E> comparator)
-
UnmodifiableSortedSet
public UnmodifiableSortedSet(Set<? extends E> c, Comparator<? super E> comparator)
-
UnmodifiableSortedSet
public UnmodifiableSortedSet(Collection<? extends E> c)
Warning: O(n**2)
-
UnmodifiableSortedSet
public UnmodifiableSortedSet(Collection<? extends E> c, Comparator<? super E> comparator)
Warning: O(n**2)
-
-
Method Detail
-
comparator
public Comparator<? super E> comparator()
- Specified by:
comparator
in interfaceSortedSet<E>
-
headSet
public SortedSet<E> headSet(E toElement)
- Specified by:
headSet
in interfaceSortedSet<E>
- Throws:
UnsupportedOperationException
-
subSet
public SortedSet<E> subSet(E fromElement, E toElement)
- Specified by:
subSet
in interfaceSortedSet<E>
- Throws:
UnsupportedOperationException
-
tailSet
public SortedSet<E> tailSet(E fromElement)
- Specified by:
tailSet
in interfaceSortedSet<E>
- Throws:
UnsupportedOperationException
-
add
public boolean add(E o)
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classArraySet<E>
- Throws:
UnsupportedOperationException
-
addUnique
public void addUnique(E o)
Description copied from class:ArraySet
Unconditionally add o to the set. This avoids the O(n) time of add(), but it's the caller's responsibility to ensure that o is not a duplicate. Any duplicate added will appear in the iterator.- Overrides:
addUnique
in classArraySet<E>
- Parameters:
o
- non-null, NPE will not be thrown- Throws:
UnsupportedOperationException
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classArraySet<E>
- Throws:
UnsupportedOperationException
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classArraySet<E>
- Throws:
UnsupportedOperationException
-
-