Class ImmutableSortedSet<E>

    • Method Detail

      • of

        public static <E> ImmutableSortedSet<E> of()
        Returns the empty immutable sorted set.
      • of

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E element)
        Returns an immutable sorted set containing a single element.
      • of

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1,
                                                                                 E e2)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to Comparable.compareTo(T), only the first one specified is included.
        Throws:
        NullPointerException - if any element is null
      • of

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1,
                                                                                 E e2,
                                                                                 E e3)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to Comparable.compareTo(T), only the first one specified is included.
        Throws:
        NullPointerException - if any element is null
      • of

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1,
                                                                                 E e2,
                                                                                 E e3,
                                                                                 E e4)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to Comparable.compareTo(T), only the first one specified is included.
        Throws:
        NullPointerException - if any element is null
      • of

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1,
                                                                                 E e2,
                                                                                 E e3,
                                                                                 E e4,
                                                                                 E e5)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to Comparable.compareTo(T), only the first one specified is included.
        Throws:
        NullPointerException - if any element is null
      • of

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1,
                                                                                 E e2,
                                                                                 E e3,
                                                                                 E e4,
                                                                                 E e5,
                                                                                 E e6,
                                                                                 E... remaining)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to Comparable.compareTo(T), only the first one specified is included.
        Throws:
        NullPointerException - if any element is null
        Since:
        3.0 (source-compatible since 2.0)
      • copyOf

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> copyOf(E[] elements)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to Comparable.compareTo(T), only the first one specified is included.
        Throws:
        NullPointerException - if any of elements is null
        Since:
        3.0
      • copyOf

        public static <E> ImmutableSortedSet<E> copyOf(Iterable<? extends E> elements)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to compareTo(), only the first one specified is included. To create a copy of a SortedSet that preserves the comparator, call copyOfSorted(java.util.SortedSet<E>) instead. This method iterates over elements at most once.

        Note that if s is a Set<String>, then ImmutableSortedSet.copyOf(s) returns an ImmutableSortedSet<String> containing each of the strings in s, while ImmutableSortedSet.of(s) returns an ImmutableSortedSet<Set<String>> containing one element (the given set itself).

        Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

        This method is not type-safe, as it may be called on elements that are not mutually comparable.

        Throws:
        ClassCastException - if the elements are not mutually comparable
        NullPointerException - if any of elements is null
      • copyOf

        public static <E> ImmutableSortedSet<E> copyOf(Collection<? extends E> elements)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to compareTo(), only the first one specified is included. To create a copy of a SortedSet that preserves the comparator, call copyOfSorted(java.util.SortedSet<E>) instead. This method iterates over elements at most once.

        Note that if s is a Set<String>, then ImmutableSortedSet.copyOf(s) returns an ImmutableSortedSet<String> containing each of the strings in s, while ImmutableSortedSet.of(s) returns an ImmutableSortedSet<Set<String>> containing one element (the given set itself).

        Note: Despite what the method name suggests, if elements is an ImmutableSortedSet, it may be returned instead of a copy.

        This method is not type-safe, as it may be called on elements that are not mutually comparable.

        This method is safe to use even when elements is a synchronized or concurrent collection that is currently being modified by another thread.

        Throws:
        ClassCastException - if the elements are not mutually comparable
        NullPointerException - if any of elements is null
        Since:
        7.0 (source-compatible since 2.0)
      • copyOf

        public static <E> ImmutableSortedSet<E> copyOf(Iterator<? extends E> elements)
        Returns an immutable sorted set containing the given elements sorted by their natural ordering. When multiple elements are equivalent according to compareTo(), only the first one specified is included.

        This method is not type-safe, as it may be called on elements that are not mutually comparable.

        Throws:
        ClassCastException - if the elements are not mutually comparable
        NullPointerException - if any of elements is null
      • copyOf

        public static <E> ImmutableSortedSet<E> copyOf(Comparator<? super E> comparator,
                                                       Iterator<? extends E> elements)
        Returns an immutable sorted set containing the given elements sorted by the given Comparator. When multiple elements are equivalent according to compareTo(), only the first one specified is included.
        Throws:
        NullPointerException - if comparator or any of elements is null
      • copyOf

        public static <E> ImmutableSortedSet<E> copyOf(Comparator<? super E> comparator,
                                                       Iterable<? extends E> elements)
        Returns an immutable sorted set containing the given elements sorted by the given Comparator. When multiple elements are equivalent according to compare(), only the first one specified is included. This method iterates over elements at most once.

        Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

        Throws:
        NullPointerException - if comparator or any of elements is null
      • copyOf

        public static <E> ImmutableSortedSet<E> copyOf(Comparator<? super E> comparator,
                                                       Collection<? extends E> elements)
        Returns an immutable sorted set containing the given elements sorted by the given Comparator. When multiple elements are equivalent according to compareTo(), only the first one specified is included.

        Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

        This method is safe to use even when elements is a synchronized or concurrent collection that is currently being modified by another thread.

        Throws:
        NullPointerException - if comparator or any of elements is null
        Since:
        7.0 (source-compatible since 2.0)
      • copyOfSorted

        public static <E> ImmutableSortedSet<E> copyOfSorted(SortedSet<E> sortedSet)
        Returns an immutable sorted set containing the elements of a sorted set, sorted by the same Comparator. That behavior differs from copyOf(Iterable), which always uses the natural ordering of the elements.

        Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

        This method is safe to use even when sortedSet is a synchronized or concurrent collection that is currently being modified by another thread.

        Throws:
        NullPointerException - if sortedSet or any of its elements is null
      • orderedBy

        public static <E> ImmutableSortedSet.Builder<E> orderedBy(Comparator<E> comparator)
        Returns a builder that creates immutable sorted sets with an explicit comparator. If the comparator has a more general type than the set being generated, such as creating a SortedSet<Integer> with a Comparator<Number>, use the ImmutableSortedSet.Builder constructor instead.
        Throws:
        NullPointerException - if comparator is null
      • reverseOrder

        public static <E extends Comparable<?>> ImmutableSortedSet.Builder<E> reverseOrder()
        Returns a builder that creates immutable sorted sets whose elements are ordered by the reverse of their natural ordering.
      • naturalOrder

        public static <E extends Comparable<?>> ImmutableSortedSet.Builder<E> naturalOrder()
        Returns a builder that creates immutable sorted sets whose elements are ordered by their natural ordering. The sorted sets use Ordering.natural() as the comparator. This method provides more type-safety than builder(), as it can be called only for classes that implement Comparable.
      • comparator

        public Comparator<? super E> comparator()
        Returns the comparator that orders the elements, which is Ordering.natural() when the natural ordering of the elements is used. Note that its behavior is not consistent with SortedSet.comparator(), which returns null to indicate natural ordering.
      • headSet

        public ImmutableSortedSet<E> headSet(E toElement)

        This method returns a serializable ImmutableSortedSet.

        The SortedSet.headSet(E) documentation states that a subset of a subset throws an IllegalArgumentException if passed a toElement greater than an earlier toElement. However, this method doesn't throw an exception in that situation, but instead keeps the original toElement.

      • subSet

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

        This method returns a serializable ImmutableSortedSet.

        The SortedSet.subSet(E, E) documentation states that a subset of a subset throws an IllegalArgumentException if passed a fromElement smaller than an earlier fromElement. However, this method doesn't throw an exception in that situation, but instead keeps the original fromElement. Similarly, this method keeps the original toElement, instead of throwing an exception, if passed a toElement greater than an earlier toElement.

      • tailSet

        public ImmutableSortedSet<E> tailSet(E fromElement)

        This method returns a serializable ImmutableSortedSet.

        The SortedSet.tailSet(E) documentation states that a subset of a subset throws an IllegalArgumentException if passed a fromElement smaller than an earlier fromElement. However, this method doesn't throw an exception in that situation, but instead keeps the original fromElement.

      • first

        public E first()
      • last

        public E last()