Class ContiguousSet<C extends Comparable>
- All Implemented Interfaces:
- Serializable,- Iterable<C>,- Collection<C>,- NavigableSet<C>,- SequencedCollection<C>,- SequencedSet<C>,- Set<C>,- SortedSet<C>
DiscreteDomain. Example:
 
ContiguousSet.create(Range.closed(5, 42), DiscreteDomain.integers())
Note that because bounded ranges over int and long values 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 as Set.hashCode() or Collections.frequency(java.util.Collection<?>, java.lang.Object)) can cause major performance problems.
- Since:
- 10.0
- Author:
- Gregory Kick
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class com.google.common.collect.ImmutableSortedSetImmutableSortedSet.Builder<E>
- 
Method SummaryModifier and TypeMethodDescriptionstatic <E> ImmutableSortedSet.Builder<E> builder()Deprecated.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 <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.abstract ContiguousSet<C> intersection(ContiguousSet<C> other) Returns the set of values that are contained in both this set and the other.range()Returns a range, closed on both ends, whose endpoints are the minimum and maximum values contained in this set.Returns the minimal range with the given boundary types for which all values in this set are contained within the range.toString()Returns a shorthand representation of the contents such as"[1..100]".Methods inherited from class com.google.common.collect.ImmutableSortedSetbuilderWithExpectedSize, ceiling, comparator, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOfSorted, descendingIterator, descendingSet, first, floor, higher, iterator, last, lower, naturalOrder, of, of, of, of, of, of, of, of, of, of, of, of, of, orderedBy, pollFirst, pollLast, reverseOrder, toImmutableSet, toImmutableSortedSetMethods inherited from class com.google.common.collect.ImmutableSetasList, equals, hashCodeMethods inherited from class com.google.common.collect.ImmutableCollectionadd, addAll, clear, contains, remove, removeAll, retainAll, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractCollectioncontainsAll, isEmpty, sizeMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.NavigableSetremoveFirst, removeLast, reversed
- 
Method Details- 
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
 
- 
closedReturns 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
 
- 
closedReturns 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
 
- 
closedOpenReturns 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
 
- 
closedOpenReturns 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
 
- 
headSetDescription copied from class:ImmutableSortedSetThis 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>
 
- 
headSet- Specified by:
- headSetin interface- NavigableSet<C extends Comparable>
- Overrides:
- headSetin class- ImmutableSortedSet<C extends Comparable>
- Since:
- 12.0
 
- 
subSetDescription copied from class:ImmutableSortedSetThis 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>
 
- 
subSet@GwtIncompatible public ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) - Specified by:
- subSetin interface- NavigableSet<C extends Comparable>
- Overrides:
- subSetin class- ImmutableSortedSet<C extends Comparable>
- Since:
- 12.0
 
- 
tailSetDescription copied from class:ImmutableSortedSetThis 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>
 
- 
tailSet- Specified by:
- tailSetin interface- NavigableSet<C extends Comparable>
- Overrides:
- tailSetin class- ImmutableSortedSet<C extends Comparable>
- Since:
- 12.0
 
- 
intersectionReturns 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.
- 
rangeReturns 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
 
- 
rangeReturns 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
 
- 
toStringReturns a shorthand representation of the contents such as"[1..100]".- Overrides:
- toStringin class- AbstractCollection<C extends Comparable>
 
- 
builderDeprecated.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
 
 
- 
create(com.google.common.collect.Range<C>, com.google.common.collect.DiscreteDomain<C>).