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 booleanadd(E o)voidaddUnique(E o)Unconditionally add o to the set.voidclear()Comparator<? super E>comparator()Efirst()SortedSet<E>headSet(E toElement)protected intindexOf(Object o)Overridden to do binary searchElast()booleanremove(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:
comparatorin interfaceSortedSet<E>
-
headSet
public SortedSet<E> headSet(E toElement)
- Specified by:
headSetin interfaceSortedSet<E>- Throws:
UnsupportedOperationException
-
subSet
public SortedSet<E> subSet(E fromElement, E toElement)
- Specified by:
subSetin interfaceSortedSet<E>- Throws:
UnsupportedOperationException
-
tailSet
public SortedSet<E> tailSet(E fromElement)
- Specified by:
tailSetin interfaceSortedSet<E>- Throws:
UnsupportedOperationException
-
add
public boolean add(E o)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classArraySet<E>- Throws:
UnsupportedOperationException
-
addUnique
public void addUnique(E o)
Description copied from class:ArraySetUnconditionally 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:
addUniquein classArraySet<E>- Parameters:
o- non-null, NPE will not be thrown- Throws:
UnsupportedOperationException
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classArraySet<E>- Throws:
UnsupportedOperationException
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classArraySet<E>- Throws:
UnsupportedOperationException
-
-