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>

- Type Parameters:
    `E` - type of elements in this set
  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 duplicate check is O(n**2).

- - ### 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 and 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 and 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 search
    `E` | `last()`
    `boolean` | `remove(Object o)`
    `SortedSet<E>` | `subSet(E fromElement, E toElement)`
    `SortedSet<E>` | `tailSet(E fromElement)`

    - ### Methods inherited from class net.i2p.util.ArraySet

      `contains, get, isEmpty, iterator, size`

    - ### 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.SortedSet

      `spliterator`

    - ### 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.Collection

      `parallelStream, removeIf, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Constructor Detail

    - #### 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)

    - #### UnmodifiableSortedSet

          public UnmodifiableSortedSet(Set<? extends E> c)

    - #### UnmodifiableSortedSet

          public UnmodifiableSortedSet(Set<? extends E> c,
                                       Comparator<? super E> comparator)

    - #### UnmodifiableSortedSet

          public UnmodifiableSortedSet(SortedSet<? extends E> c)

    - #### UnmodifiableSortedSet

          public UnmodifiableSortedSet(SortedSet<? extends E> c,
                                       Comparator<? super E> comparator)

  - ### Method Detail

    - #### add

          public boolean add(E o)

      Specified by:
        `add` in interface `Collection<E>`
      Specified by:
        `add` in interface `Set<E>`
      Overrides:
        `add` in class `ArraySet<E>`
      Parameters:
        `o` - the element to add
      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 class `ArraySet<E>`
      Parameters:
        `o` - non-null, NPE will not be thrown
      Throws:
        `UnsupportedOperationException`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Collection<E>`
      Specified by:
        `clear` in interface `Set<E>`
      Overrides:
        `clear` in class `ArraySet<E>`
      Throws:
        `UnsupportedOperationException`

    - #### comparator

          public Comparator<? super E> comparator()

      Specified by:
        `comparator` in interface `SortedSet<E>`

    - #### first

          public E first()

      Specified by:
        `first` in interface `SortedSet<E>`

    - #### headSet

          public SortedSet<E> headSet(E toElement)

      Specified by:
        `headSet` in interface `SortedSet<E>`
      Throws:
        `UnsupportedOperationException`

    - #### indexOf

          protected int indexOf(Object o)

      Overridden to do binary search
      Overrides:
        `indexOf` in class `ArraySet<E>`
      Parameters:
        `o` - the object to find the index of
      Returns:
        -1 if not found or if o is null

    - #### last

          public E last()

      Specified by:
        `last` in interface `SortedSet<E>`

    - #### remove

          public boolean remove(Object o)

      Specified by:
        `remove` in interface `Collection<E>`
      Specified by:
        `remove` in interface `Set<E>`
      Overrides:
        `remove` in class `ArraySet<E>`
      Throws:
        `UnsupportedOperationException`

    - #### subSet

          public SortedSet<E> subSet(E fromElement,
                                     E toElement)

      Specified by:
        `subSet` in interface `SortedSet<E>`
      Throws:
        `UnsupportedOperationException`

    - #### tailSet

          public SortedSet<E> tailSet(E fromElement)

      Specified by:
        `tailSet` in interface `SortedSet<E>`
      Throws:
        `UnsupportedOperationException`