Class ImmutableSortedSet<E>

    • Method Detail

      • of

        public static <E> ImmutableSortedSet<E> of()
        Returns the empty immutable sorted set.
        Type Parameters:
        E - the Set's element type
        Returns:
        an empty Set
      • of

        public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of​(E element)
        Returns an immutable sorted set containing a single element.
        Type Parameters:
        E - the Set's element type
        Parameters:
        element - the single element
        Returns:
        a Set containing the specified 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.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        Returns:
        a Set containing the specified elements
        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.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        Returns:
        a Set containing the specified elements
        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.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        Returns:
        a Set containing the specified elements
        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.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        Returns:
        a Set containing the specified elements
        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.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        remaining - the seventh element
        Returns:
        a Set containing the specified elements
        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.

        Type Parameters:
        E - the Set's element type
        Parameters:
        elements - a Collection from which elements are drawn, must be non-null
        Returns:
        a Set containing the elements of the given Collection
        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
      • comparator

        public Comparator<? super Ecomparator()
        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.
        Specified by:
        comparator in interface SortedSet<E>
        Returns:
        the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements
      • headSet

        public ImmutableSortedSet<EheadSet​(E toElement)
        Returns a view of the portion of this set whose elements are strictly less than toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Equivalent to headSet(toElement, false).

        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.

        Specified by:
        headSet in interface NavigableSet<E>
        Specified by:
        headSet in interface SortedSet<E>
        Parameters:
        toElement - high endpoint (exclusive) of the returned set
        Returns:
        a view of the portion of this set whose elements are strictly less than toElement
      • headSet

        public ImmutableSortedSet<EheadSet​(E toElement,
                                             boolean inclusive)
        Description copied from interface: java.util.NavigableSet
        Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        headSet in interface NavigableSet<E>
        Parameters:
        toElement - high endpoint of the returned set
        inclusive - true if the high endpoint is to be included in the returned view
        Returns:
        a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement
        Since:
        12.0
      • subSet

        public ImmutableSortedSet<EsubSet​(E fromElement,
                                            E toElement)
        Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. (If fromElement and toElement are equal, the returned set is empty.) The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Equivalent to subSet(fromElement, true, toElement, false).

        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.

        Specified by:
        subSet in interface NavigableSet<E>
        Specified by:
        subSet in interface SortedSet<E>
        Parameters:
        fromElement - low endpoint (inclusive) of the returned set
        toElement - high endpoint (exclusive) of the returned set
        Returns:
        a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive
      • subSet

        @GwtIncompatible
        public ImmutableSortedSet<EsubSet​(E fromElement,
                                            boolean fromInclusive,
                                            E toElement,
                                            boolean toInclusive)
        Description copied from interface: java.util.NavigableSet
        Returns a view of the portion of this set whose elements range from fromElement to toElement. If fromElement and toElement are equal, the returned set is empty unless fromInclusive and toInclusive are both true. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        subSet in interface NavigableSet<E>
        Parameters:
        fromElement - low endpoint of the returned set
        fromInclusive - true if the low endpoint is to be included in the returned view
        toElement - high endpoint of the returned set
        toInclusive - true if the high endpoint is to be included in the returned view
        Returns:
        a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive
        Since:
        12.0
      • tailSet

        public ImmutableSortedSet<EtailSet​(E fromElement)
        Returns a view of the portion of this set whose elements are greater than or equal to fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Equivalent to tailSet(fromElement, true).

        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.

        Specified by:
        tailSet in interface NavigableSet<E>
        Specified by:
        tailSet in interface SortedSet<E>
        Parameters:
        fromElement - low endpoint (inclusive) of the returned set
        Returns:
        a view of the portion of this set whose elements are greater than or equal to fromElement
      • tailSet

        public ImmutableSortedSet<EtailSet​(E fromElement,
                                             boolean inclusive)
        Description copied from interface: java.util.NavigableSet
        Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        tailSet in interface NavigableSet<E>
        Parameters:
        fromElement - low endpoint of the returned set
        inclusive - true if the low endpoint is to be included in the returned view
        Returns:
        a view of the portion of this set whose elements are greater than or equal to fromElement
        Since:
        12.0
      • lower

        @GwtIncompatible
        public E lower​(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
        Specified by:
        lower in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the greatest element less than e, or null if there is no such element
        Since:
        12.0
      • floor

        public E floor​(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.
        Specified by:
        floor in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the greatest element less than or equal to e, or null if there is no such element
        Since:
        12.0
      • ceiling

        public E ceiling​(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
        Specified by:
        ceiling in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the least element greater than or equal to e, or null if there is no such element
        Since:
        12.0
      • higher

        @GwtIncompatible
        public E higher​(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the least element in this set strictly greater than the given element, or null if there is no such element.
        Specified by:
        higher in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the least element greater than e, or null if there is no such element
        Since:
        12.0
      • first

        public E first()
        Description copied from interface: java.util.SortedSet
        Returns the first (lowest) element currently in this set.
        Specified by:
        first in interface SortedSet<E>
        Returns:
        the first (lowest) element currently in this set
      • last

        public E last()
        Description copied from interface: java.util.SortedSet
        Returns the last (highest) element currently in this set.
        Specified by:
        last in interface SortedSet<E>
        Returns:
        the last (highest) element currently in this set
      • descendingSet

        @GwtIncompatible
        public ImmutableSortedSet<EdescendingSet()
        Description copied from interface: java.util.NavigableSet
        Returns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while an iteration over either set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined.

        The returned set has an ordering equivalent to Collections.reverseOrder(comparator()). The expression s.descendingSet().descendingSet() returns a view of s essentially equivalent to s.

        Specified by:
        descendingSet in interface NavigableSet<E>
        Returns:
        a reverse order view of this set
        Since:
        12.0
      • of

        @Deprecated
        public static <E> ImmutableSortedSet<E> of​(E element)
        Deprecated.
        Pass a parameter of type Comparable to use of(Comparable).
        Not supported. You are attempting to create a set that may contain a non-Comparable element. Proper calls will resolve to the version in ImmutableSortedSet, not this dummy version.
        Type Parameters:
        E - the Set's element type
        Parameters:
        element - the single element
        Returns:
        a Set containing the specified element
        Throws:
        UnsupportedOperationException - always
      • of

        @Deprecated
        public static <E> ImmutableSortedSet<E> of​(E e1,
                                                   E e2)
        Deprecated.
        Pass the parameters of type Comparable to use of(Comparable, Comparable).
        Not supported. You are attempting to create a set that may contain a non-Comparable element. Proper calls will resolve to the version in ImmutableSortedSet, not this dummy version.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        Returns:
        a Set containing the specified elements
        Throws:
        UnsupportedOperationException - always
      • of

        @Deprecated
        public static <E> ImmutableSortedSet<E> of​(E e1,
                                                   E e2,
                                                   E e3)
        Deprecated.
        Pass the parameters of type Comparable to use of(Comparable, Comparable, Comparable).
        Not supported. You are attempting to create a set that may contain a non-Comparable element. Proper calls will resolve to the version in ImmutableSortedSet, not this dummy version.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        Returns:
        a Set containing the specified elements
        Throws:
        UnsupportedOperationException - always
      • of

        @Deprecated
        public static <E> ImmutableSortedSet<E> of​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4)
        Deprecated.
        Pass the parameters of type Comparable to use of(Comparable, Comparable, Comparable, Comparable).
        Not supported. You are attempting to create a set that may contain a non-Comparable element. Proper calls will resolve to the version in ImmutableSortedSet, not this dummy version.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        Returns:
        a Set containing the specified elements
        Throws:
        UnsupportedOperationException - always
      • of

        @Deprecated
        public static <E> ImmutableSortedSet<E> of​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4,
                                                   E e5)
        Deprecated.
        Pass the parameters of type Comparable to use of( Comparable, Comparable, Comparable, Comparable, Comparable).
        Not supported. You are attempting to create a set that may contain a non-Comparable element. Proper calls will resolve to the version in ImmutableSortedSet, not this dummy version.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        Returns:
        a Set containing the specified elements
        Throws:
        UnsupportedOperationException - always
      • of

        @Deprecated
        public static <E> ImmutableSortedSet<E> of​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4,
                                                   E e5,
                                                   E e6,
                                                   E... remaining)
        Deprecated.
        Not supported. You are attempting to create a set that may contain a non-Comparable element. Proper calls will resolve to the version in ImmutableSortedSet, not this dummy version.
        Type Parameters:
        E - the Set's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        remaining - the seventh element
        Returns:
        a Set containing the specified elements
        Throws:
        UnsupportedOperationException - always
      • copyOf

        @Deprecated
        public static <E> ImmutableSortedSet<E> copyOf​(E[] elements)
        Deprecated.
        Pass parameters of type Comparable to use copyOf(Comparable[]).
        Not supported. You are attempting to create a set that may contain non-Comparable elements. Proper calls will resolve to the version in ImmutableSortedSet, not this dummy version.
        Throws:
        UnsupportedOperationException - always