Type Parameters:
E - type of elements in this set
All Implemented Interfaces:
Iterable<E>, Collection<E>, SequencedCollection<E>, SequencedSet<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).

  • Field Details

    • comp

      private final Comparator<? super E> comp
      The order the set is kept in.
    • initialized

      private final boolean initialized
      True once the set being wrapped has been supplied
  • Constructor Details

    • UnmodifiableSortedSet

      public UnmodifiableSortedSet(SortedSet<? extends E> c)
      Copy of the given sorted set.
      Parameters:
      c - sorted set to copy, must already be sorted
    • UnmodifiableSortedSet

      public UnmodifiableSortedSet(SortedSet<? extends E> c, Comparator<? super E> comparator)
      Copy of the given sorted set with the given comparator.
      Parameters:
      c - sorted set to copy, must already be sorted
      comparator - comparator for ordering
    • UnmodifiableSortedSet

      public UnmodifiableSortedSet(Set<? extends E> c)
      Copy of the given set, sorted.
      Parameters:
      c - set to copy and sort
    • UnmodifiableSortedSet

      public UnmodifiableSortedSet(Set<? extends E> c, Comparator<? super E> comparator)
      Copy of the given set, sorted with the given comparator.
      Parameters:
      c - set to copy and sort
      comparator - comparator for ordering
    • UnmodifiableSortedSet

      public UnmodifiableSortedSet(Collection<? extends E> c)
      Warning: O(n**2).
      Parameters:
      c - collection to copy and sort
    • UnmodifiableSortedSet

      public UnmodifiableSortedSet(Collection<? extends E> c, Comparator<? super E> comparator)
      Warning: O(n**2).
      Parameters:
      c - collection to copy and sort
      comparator - comparator for ordering
  • Method Details