Class ContiguousSet<C extends Comparable>
- java.lang.Object
- 
- java.util.AbstractCollection<E>
- 
- com.google.common.collect.ImmutableCollection<E>
- 
- com.google.common.collect.ImmutableSet<E>
- 
- com.google.common.collect.ImmutableSortedSet<C>
- 
- com.google.common.collect.ContiguousSet<C>
 
 
 
 
 
- 
- All Implemented Interfaces:
- Serializable,- Iterable<C>,- Collection<C>,- NavigableSet<C>,- Set<C>,- SortedSet<C>
 
 @GwtCompatible(emulated=true) public abstract class ContiguousSet<C extends Comparable> extends ImmutableSortedSet<C> A sorted set of contiguous values in a givenDiscreteDomain. Example:ContiguousSet.create(Range.closed(5, 42), DiscreteDomain.integers())Note that because bounded ranges over intandlongvalues are so common, this particular example can be written as just:ContiguousSet.closed(5, 42)Warning: Be extremely careful what you do with conceptually large instances (such as ContiguousSet.create(Range.greaterThan(0), DiscreteDomain.integers()). Certain operations on such a set can be performed efficiently, but others (such asSet.hashCode()orCollections.frequency(java.util.Collection<?>, java.lang.Object)) can cause major performance problems.- Since:
- 10.0
- Author:
- Gregory Kick
- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class com.google.common.collect.ImmutableSortedSetImmutableSortedSet.Builder<E>
 
- 
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ImmutableList<E>asList()Returns anImmutableListcontaining the same elements, in the same order, as this collection.static <E> ImmutableSortedSet.Builder<E>builder()static <E> ImmutableSortedSet.Builder<E>builderWithExpectedSize(int expectedSize)Deprecated.Not supported by ImmutableSortedSet.static ContiguousSet<Integer>closed(int lower, int upper)Returns a nonempty contiguous set containing allintvalues fromlower(inclusive) toupper(inclusive).static ContiguousSet<Long>closed(long lower, long upper)Returns a nonempty contiguous set containing alllongvalues fromlower(inclusive) toupper(inclusive).static ContiguousSet<Integer>closedOpen(int lower, int upper)Returns a contiguous set containing allintvalues fromlower(inclusive) toupper(exclusive).static ContiguousSet<Long>closedOpen(long lower, long upper)Returns a contiguous set containing alllongvalues fromlower(inclusive) toupper(exclusive).static <E> ImmutableSortedSet<E>copyOf(E[] elements)Deprecated.Pass parameters of typeComparableto useImmutableSortedSet.copyOf(Comparable[]).static <C extends Comparable>
 ContiguousSet<C>create(Range<C> range, DiscreteDomain<C> domain)Returns aContiguousSetcontaining the same values in the given domain contained by the range.ContiguousSet<C>headSet(C toElement)Returns a view of the portion of this set whose elements are strictly less thantoElement.ContiguousSet<C>headSet(C toElement, boolean inclusive)Returns a view of the portion of this set whose elements are less than (or equal to, ifinclusiveis true)toElement.abstract ContiguousSet<C>intersection(ContiguousSet<C> other)Returns the set of values that are contained in both this set and the other.static <E> ImmutableSortedSet<E>of(E element)Deprecated.Pass a parameter of typeComparableto useImmutableSortedSet.of(Comparable).static <E> ImmutableSortedSet<E>of(E e1, E e2)Deprecated.Pass the parameters of typeComparableto useImmutableSortedSet.of(Comparable, Comparable).static <E> ImmutableSortedSet<E>of(E e1, E e2, E e3)Deprecated.Pass the parameters of typeComparableto useImmutableSortedSet.of(Comparable, Comparable, Comparable).static <E> ImmutableSortedSet<E>of(E e1, E e2, E e3, E e4)Deprecated.Pass the parameters of typeComparableto useImmutableSortedSet.of(Comparable, Comparable, Comparable, Comparable).static <E> ImmutableSortedSet<E>of(E e1, E e2, E e3, E e4, E e5)Deprecated.Pass the parameters of typeComparableto useImmutableSortedSet.of( Comparable, Comparable, Comparable, Comparable, Comparable).static <E> ImmutableSortedSet<E>of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining)Deprecated.Pass the parameters of typeComparableto useImmutableSortedSet.of(Comparable, Comparable, Comparable, Comparable, Comparable, Comparable, Comparable...).abstract Range<C>range()Returns a range, closed on both ends, whose endpoints are the minimum and maximum values contained in this set.abstract Range<C>range(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.ContiguousSet<C>subSet(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)Returns a view of the portion of this set whose elements range fromfromElementtotoElement.ContiguousSet<C>subSet(C fromElement, C toElement)Returns a view of the portion of this set whose elements range fromfromElement, inclusive, totoElement, exclusive.ContiguousSet<C>tailSet(C fromElement)Returns a view of the portion of this set whose elements are greater than or equal tofromElement.ContiguousSet<C>tailSet(C fromElement, boolean inclusive)Returns a view of the portion of this set whose elements are greater than (or equal to, ifinclusiveis true)fromElement.static <E> Collector<E,?,ImmutableSet<E>>toImmutableSet()StringtoString()Returns a short-hand representation of the contents such as"[1..100]".- 
Methods inherited from class com.google.common.collect.ImmutableSortedSetceiling, comparator, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOfSorted, descendingIterator, descendingSet, first, floor, higher, iterator, last, lower, naturalOrder, of, of, of, of, of, of, of, orderedBy, pollFirst, pollLast, reverseOrder, spliterator, toImmutableSortedSet
 - 
Methods inherited from class com.google.common.collect.ImmutableSetequals, hashCode
 - 
Methods inherited from class com.google.common.collect.ImmutableCollectionadd, addAll, clear, contains, remove, removeAll, removeIf, retainAll, toArray, toArray
 - 
Methods inherited from class java.util.AbstractCollectioncontainsAll, isEmpty, size
 - 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface java.util.CollectionparallelStream, removeIf, stream, toArray
 
- 
 
- 
- 
- 
Method Detail- 
createpublic static <C extends Comparable> ContiguousSet<C> create(Range<C> range, DiscreteDomain<C> domain) Returns aContiguousSetcontaining the same values in the given domain contained by the range.- Throws:
- IllegalArgumentException- if neither range nor the domain has a lower bound, or if neither has an upper bound
- Since:
- 13.0
 
 - 
closed@Beta public static ContiguousSet<Integer> closed(int lower, int upper) Returns a nonempty contiguous set containing allintvalues fromlower(inclusive) toupper(inclusive). (These are the same values contained inRange.closed(lower, upper).)- Throws:
- IllegalArgumentException- if- loweris greater than- upper
- Since:
- 23.0
 
 - 
closed@Beta public static ContiguousSet<Long> closed(long lower, long upper) Returns a nonempty contiguous set containing alllongvalues fromlower(inclusive) toupper(inclusive). (These are the same values contained inRange.closed(lower, upper).)- Throws:
- IllegalArgumentException- if- loweris greater than- upper
- Since:
- 23.0
 
 - 
closedOpen@Beta public static ContiguousSet<Integer> closedOpen(int lower, int upper) Returns a contiguous set containing allintvalues fromlower(inclusive) toupper(exclusive). If the endpoints are equal, an empty set is returned. (These are the same values contained inRange.closedOpen(lower, upper).)- Throws:
- IllegalArgumentException- if- loweris greater than- upper
- Since:
- 23.0
 
 - 
closedOpen@Beta public static ContiguousSet<Long> closedOpen(long lower, long upper) Returns a contiguous set containing alllongvalues fromlower(inclusive) toupper(exclusive). If the endpoints are equal, an empty set is returned. (These are the same values contained inRange.closedOpen(lower, upper).)- Throws:
- IllegalArgumentException- if- loweris greater than- upper
- Since:
- 23.0
 
 - 
headSetpublic ContiguousSet<C> headSet(C toElement) Description copied from class:ImmutableSortedSetReturns a view of the portion of this set whose elements are strictly less thantoElement. 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 IllegalArgumentExceptionon 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 anIllegalArgumentExceptionif passed atoElementgreater than an earliertoElement. However, this method doesn't throw an exception in that situation, but instead keeps the originaltoElement.- Specified by:
- headSetin interface- NavigableSet<C extends Comparable>
- Specified by:
- headSetin interface- SortedSet<C extends Comparable>
- Overrides:
- headSetin 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<C> headSet(C toElement, boolean inclusive) Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements are less than (or equal to, ifinclusiveis 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 IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
- headSetin interface- NavigableSet<C extends Comparable>
- Overrides:
- headSetin class- ImmutableSortedSet<C extends Comparable>
- Parameters:
- toElement- high endpoint of the returned set
- inclusive-- trueif 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 inclusiveis true)toElement
- Since:
- 12.0
 
 - 
subSetpublic ContiguousSet<C> subSet(C fromElement, C toElement) Description copied from class:ImmutableSortedSetReturns a view of the portion of this set whose elements range fromfromElement, inclusive, totoElement, exclusive. (IffromElementandtoElementare 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 IllegalArgumentExceptionon 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 anIllegalArgumentExceptionif passed afromElementsmaller than an earlierfromElement. However, this method doesn't throw an exception in that situation, but instead keeps the originalfromElement. Similarly, this method keeps the originaltoElement, instead of throwing an exception, if passed atoElementgreater than an earliertoElement.- Specified by:
- subSetin interface- NavigableSet<C extends Comparable>
- Specified by:
- subSetin interface- SortedSet<C extends Comparable>
- Overrides:
- subSetin 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, totoElement, exclusive
 
 - 
subSet@GwtIncompatible public ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements range fromfromElementtotoElement. IffromElementandtoElementare equal, the returned set is empty unlessfromInclusiveandtoInclusiveare 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 IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
- subSetin interface- NavigableSet<C extends Comparable>
- Overrides:
- subSetin class- ImmutableSortedSet<C extends Comparable>
- Parameters:
- fromElement- low endpoint of the returned set
- fromInclusive-- trueif the low endpoint is to be included in the returned view
- toElement- high endpoint of the returned set
- toInclusive-- trueif 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, totoElement, exclusive
- Since:
- 12.0
 
 - 
tailSetpublic ContiguousSet<C> tailSet(C fromElement) Description copied from class:ImmutableSortedSetReturns a view of the portion of this set whose elements are greater than or equal tofromElement. 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 IllegalArgumentExceptionon 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 anIllegalArgumentExceptionif passed afromElementsmaller than an earlierfromElement. However, this method doesn't throw an exception in that situation, but instead keeps the originalfromElement.- Specified by:
- tailSetin interface- NavigableSet<C extends Comparable>
- Specified by:
- tailSetin interface- SortedSet<C extends Comparable>
- Overrides:
- tailSetin 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<C> tailSet(C fromElement, boolean inclusive) Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements are greater than (or equal to, ifinclusiveis 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 IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
- tailSetin interface- NavigableSet<C extends Comparable>
- Overrides:
- tailSetin class- ImmutableSortedSet<C extends Comparable>
- Parameters:
- fromElement- low endpoint of the returned set
- inclusive-- trueif 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
 
 - 
intersectionpublic abstract ContiguousSet<C> intersection(ContiguousSet<C> other) Returns the set of values that are contained in both this set and the other.This method should always be used instead of Sets.intersection(java.util.Set<E>, java.util.Set<?>)forContiguousSetinstances.
 - 
rangepublic abstract Range<C> range() Returns a range, closed on both ends, whose endpoints are the minimum and maximum values contained in this set. This is equivalent torange(CLOSED, CLOSED).- Throws:
- NoSuchElementException- if this set is empty
 
 - 
rangepublic abstract Range<C> range(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.OPENis requested for a domain minimum or maximum. For example, ifsetwas created from the range[1..Integer.MAX_VALUE]thenset.range(CLOSED, OPEN)must return[1..∞).- Throws:
- NoSuchElementException- if this set is empty
 
 - 
toStringpublic String toString() Returns a short-hand representation of the contents such as"[1..100]".- Overrides:
- toStringin class- AbstractCollection<C extends Comparable>
- Returns:
- a string representation of this collection
 
 - 
builder@Deprecated public static <E> ImmutableSortedSet.Builder<E> builder() Deprecated.Not supported.ContiguousSetinstances are constructed withcreate(com.google.common.collect.Range<C>, com.google.common.collect.DiscreteDomain<C>). This method exists only to hideImmutableSet.builder()from consumers ofContiguousSet.- Throws:
- UnsupportedOperationException- always
 
 - 
toImmutableSet@Deprecated public static <E> Collector<E,?,ImmutableSet<E>> toImmutableSet() Not supported. UseImmutableSortedSet.toImmutableSortedSet(java.util.Comparator<? super E>)instead. This method exists only to hideImmutableSet.toImmutableSet()from consumers ofImmutableSortedSet.- Throws:
- UnsupportedOperationException- always
- Since:
- 21.0
 
 - 
builderWithExpectedSize@Deprecated public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expectedSize) Deprecated.Not supported by ImmutableSortedSet.Not supported. This method exists only to hideImmutableSet.builderWithExpectedSize(int)from consumers ofImmutableSortedSet.- Throws:
- UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedSet<E> of(E element) Deprecated.Pass a parameter of typeComparableto useImmutableSortedSet.of(Comparable).Not supported. You are attempting to create a set that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedSet, not this dummy version.- Type Parameters:
- E- the- Set's element type
- Parameters:
- element- the single element
- Returns:
- a Setcontaining the specified element
- Throws:
- UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2) Deprecated.Pass the parameters of typeComparableto useImmutableSortedSet.of(Comparable, Comparable).Not supported. You are attempting to create a set that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedSet, not this dummy version.- Type Parameters:
- E- the- Set's element type
- Parameters:
- e1- the first element
- e2- the second element
- Returns:
- a Setcontaining 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 typeComparableto useImmutableSortedSet.of(Comparable, Comparable, Comparable).Not supported. You are attempting to create a set that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedSet, 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 Setcontaining 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 typeComparableto useImmutableSortedSet.of(Comparable, Comparable, Comparable, Comparable).Not supported. You are attempting to create a set that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedSet, 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 Setcontaining 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 typeComparableto useImmutableSortedSet.of( Comparable, Comparable, Comparable, Comparable, Comparable).Not supported. You are attempting to create a set that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedSet, 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 Setcontaining 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.Pass the parameters of typeComparableto useImmutableSortedSet.of(Comparable, Comparable, Comparable, Comparable, Comparable, Comparable, Comparable...).Not supported. You are attempting to create a set that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedSet, 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 Setcontaining the specified elements
- Throws:
- UnsupportedOperationException- always
 
 - 
copyOf@Deprecated public static <E> ImmutableSortedSet<E> copyOf(E[] elements) Deprecated.Pass parameters of typeComparableto useImmutableSortedSet.copyOf(Comparable[]).Not supported. You are attempting to create a set that may contain non-Comparableelements. Proper calls will resolve to the version inImmutableSortedSet, not this dummy version.- Throws:
- UnsupportedOperationException- always
 
 - 
asListpublic ImmutableList<E> asList() Description copied from class:ImmutableCollectionReturns anImmutableListcontaining 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:
- asListin class- ImmutableCollection<E>
 
 
- 
 
-