Class ContiguousSet<C extends Comparable>

    • Method Detail

      • closed

        @Beta
        public static ContiguousSet<Integerclosed​(int lower,
                                                    int upper)
        Returns a nonempty contiguous set containing all int values from lower (inclusive) to upper (inclusive). (These are the same values contained in Range.closed(lower, upper).)
        Throws:
        IllegalArgumentException - if lower is greater than upper
        Since:
        23.0
      • closed

        @Beta
        public static ContiguousSet<Longclosed​(long lower,
                                                 long upper)
        Returns a nonempty contiguous set containing all long values from lower (inclusive) to upper (inclusive). (These are the same values contained in Range.closed(lower, upper).)
        Throws:
        IllegalArgumentException - if lower is greater than upper
        Since:
        23.0
      • closedOpen

        @Beta
        public static ContiguousSet<IntegerclosedOpen​(int lower,
                                                        int upper)
        Returns a contiguous set containing all int values from lower (inclusive) to upper (exclusive). If the endpoints are equal, an empty set is returned. (These are the same values contained in Range.closedOpen(lower, upper).)
        Throws:
        IllegalArgumentException - if lower is greater than upper
        Since:
        23.0
      • closedOpen

        @Beta
        public static ContiguousSet<LongclosedOpen​(long lower,
                                                     long upper)
        Returns a contiguous set containing all long values from lower (inclusive) to upper (exclusive). If the endpoints are equal, an empty set is returned. (These are the same values contained in Range.closedOpen(lower, upper).)
        Throws:
        IllegalArgumentException - if lower is greater than upper
        Since:
        23.0
      • headSet

        public ContiguousSet<CheadSet​(C toElement)
        Description copied from class: ImmutableSortedSet
        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<C extends Comparable>
        Specified by:
        headSet in interface SortedSet<C extends Comparable>
        Overrides:
        headSet in class ImmutableSortedSet<C extends Comparable>
        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

        @GwtIncompatible
        public ContiguousSet<CheadSet​(C 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<C extends Comparable>
        Overrides:
        headSet in class ImmutableSortedSet<C extends Comparable>
        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 ContiguousSet<CsubSet​(C fromElement,
                                       C toElement)
        Description copied from class: ImmutableSortedSet
        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<C extends Comparable>
        Specified by:
        subSet in interface SortedSet<C extends Comparable>
        Overrides:
        subSet in class ImmutableSortedSet<C extends Comparable>
        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 ContiguousSet<CsubSet​(C fromElement,
                                       boolean fromInclusive,
                                       C 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<C extends Comparable>
        Overrides:
        subSet in class ImmutableSortedSet<C extends Comparable>
        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 ContiguousSet<CtailSet​(C fromElement)
        Description copied from class: ImmutableSortedSet
        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<C extends Comparable>
        Specified by:
        tailSet in interface SortedSet<C extends Comparable>
        Overrides:
        tailSet in class ImmutableSortedSet<C extends Comparable>
        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

        @GwtIncompatible
        public ContiguousSet<CtailSet​(C 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<C extends Comparable>
        Overrides:
        tailSet in class ImmutableSortedSet<C extends Comparable>
        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
      • range

        public abstract Range<Crange()
        Returns a range, closed on both ends, whose endpoints are the minimum and maximum values contained in this set. This is equivalent to range(CLOSED, CLOSED).
        Throws:
        NoSuchElementException - if this set is empty
      • range

        public abstract Range<Crange​(BoundType lowerBoundType,
                                       BoundType upperBoundType)
        Returns the minimal range with the given boundary types for which all values in this set are contained within the range.

        Note that this method will return ranges with unbounded endpoints if BoundType.OPEN is requested for a domain minimum or maximum. For example, if set was created from the range [1..Integer.MAX_VALUE] then set.range(CLOSED, OPEN) must return [1..∞).

        Throws:
        NoSuchElementException - if this set is empty
      • of

        @Deprecated
        public static <E> ImmutableSortedSet<E> of​(E element)
        Deprecated.
        Pass a parameter of type Comparable to use ImmutableSortedSet.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 ImmutableSortedSet.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 ImmutableSortedSet.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 ImmutableSortedSet.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
      • asList

        public ImmutableList<E> asList()
        Description copied from class: ImmutableCollection
        Returns an ImmutableList containing the same elements, in the same order, as this collection.

        Performance note: in most cases this method can return quickly without actually copying anything. The exact circumstances under which the copy is performed are undefined and subject to change.

        Overrides:
        asList in class ImmutableCollection<E>