public abstract class ContiguousSet<C extends java.lang.Comparable> extends ImmutableSortedSet<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.
ImmutableSortedSet.Builder<E>ImmutableSet.CachingAsList<E>, ImmutableSet.Indexed<E>| Modifier and Type | Field and Description |
|---|---|
(package private) DiscreteDomain<C> |
domain |
comparator, descendingSet, SPLITERATOR_CHARACTERISTICSMAX_TABLE_SIZE| Constructor and Description |
|---|
ContiguousSet(DiscreteDomain<C> domain) |
| Modifier and Type | Method and Description |
|---|---|
static <E> ImmutableSortedSet.Builder<E> |
builder()
|
static ContiguousSet<java.lang.Integer> |
closed(int lower,
int upper)
Returns a nonempty contiguous set containing all
int values from lower
(inclusive) to upper (inclusive). |
static ContiguousSet<java.lang.Long> |
closed(long lower,
long upper)
Returns a nonempty contiguous set containing all
long values from lower
(inclusive) to upper (inclusive). |
static ContiguousSet<java.lang.Integer> |
closedOpen(int lower,
int upper)
Returns a contiguous set containing all
int values from lower (inclusive) to
upper (exclusive). |
static ContiguousSet<java.lang.Long> |
closedOpen(long lower,
long upper)
Returns a contiguous set containing all
long values from lower (inclusive) to
upper (exclusive). |
static <C extends java.lang.Comparable> |
create(Range<C> range,
DiscreteDomain<C> domain)
Returns a
ContiguousSet containing the same values in the given domain contained by the range. |
(package private) ImmutableSortedSet<C> |
createDescendingSet() |
ContiguousSet<C> |
headSet(C toElement) |
ContiguousSet<C> |
headSet(C toElement,
boolean inclusive) |
(package private) abstract ContiguousSet<C> |
headSetImpl(C toElement,
boolean inclusive) |
abstract ContiguousSet<C> |
intersection(ContiguousSet<C> other)
Returns the set of values that are contained in both this set and the other.
|
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) |
ContiguousSet<C> |
subSet(C fromElement,
C toElement) |
(package private) abstract ContiguousSet<C> |
subSetImpl(C fromElement,
boolean fromInclusive,
C toElement,
boolean toInclusive) |
ContiguousSet<C> |
tailSet(C fromElement) |
ContiguousSet<C> |
tailSet(C fromElement,
boolean inclusive) |
(package private) abstract ContiguousSet<C> |
tailSetImpl(C fromElement,
boolean inclusive) |
java.lang.String |
toString()
Returns a short-hand representation of the contents such as
"[1..100]". |
ceiling, comparator, construct, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOfSorted, descendingIterator, descendingSet, emptySet, first, floor, higher, indexOf, iterator, last, lower, naturalOrder, of, of, of, of, of, of, of, orderedBy, pollFirst, pollLast, reverseOrder, spliterator, toImmutableSortedSet, unsafeCompare, unsafeCompare, writeReplacebuilderWithExpectedSize, toImmutableSetasList, createAsListchooseTableSize, equals, hashCode, isHashCodeFastadd, addAll, clear, contains, copyIntoArray, internalArray, internalArrayEnd, internalArrayStart, isPartialView, remove, removeAll, removeIf, retainAll, toArray, toArrayclone, finalize, getClass, notify, notifyAll, wait, wait, waitfinal DiscreteDomain<C extends java.lang.Comparable> domain
ContiguousSet(DiscreteDomain<C> domain)
public static <C extends java.lang.Comparable> ContiguousSet<C> create(Range<C> range, DiscreteDomain<C> domain)
ContiguousSet containing the same values in the given domain contained by the range.java.lang.IllegalArgumentException - if neither range nor the domain has a lower bound, or if
neither has an upper boundpublic static ContiguousSet<java.lang.Integer> closed(int lower, int upper)
int values from lower
(inclusive) to upper (inclusive). (These are the same values contained in Range.closed(lower, upper).)java.lang.IllegalArgumentException - if lower is greater than upperpublic static ContiguousSet<java.lang.Long> closed(long lower, long upper)
long values from lower
(inclusive) to upper (inclusive). (These are the same values contained in Range.closed(lower, upper).)java.lang.IllegalArgumentException - if lower is greater than upperpublic static ContiguousSet<java.lang.Integer> closedOpen(int lower, int upper)
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).)java.lang.IllegalArgumentException - if lower is greater than upperpublic static ContiguousSet<java.lang.Long> closedOpen(long lower, long upper)
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).)java.lang.IllegalArgumentException - if lower is greater than upperpublic ContiguousSet<C> headSet(C toElement)
ImmutableSortedSetThis 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.
headSet in interface java.util.NavigableSet<C extends java.lang.Comparable>headSet in interface java.util.SortedSet<C extends java.lang.Comparable>headSet in class ImmutableSortedSet<C extends java.lang.Comparable>public ContiguousSet<C> headSet(C toElement, boolean inclusive)
headSet in interface java.util.NavigableSet<C extends java.lang.Comparable>headSet in class ImmutableSortedSet<C extends java.lang.Comparable>public ContiguousSet<C> subSet(C fromElement, C toElement)
ImmutableSortedSetThis 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.
subSet in interface java.util.NavigableSet<C extends java.lang.Comparable>subSet in interface java.util.SortedSet<C extends java.lang.Comparable>subSet in class ImmutableSortedSet<C extends java.lang.Comparable>public ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)
subSet in interface java.util.NavigableSet<C extends java.lang.Comparable>subSet in class ImmutableSortedSet<C extends java.lang.Comparable>public ContiguousSet<C> tailSet(C fromElement)
ImmutableSortedSetThis 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.
tailSet in interface java.util.NavigableSet<C extends java.lang.Comparable>tailSet in interface java.util.SortedSet<C extends java.lang.Comparable>tailSet in class ImmutableSortedSet<C extends java.lang.Comparable>public ContiguousSet<C> tailSet(C fromElement, boolean inclusive)
tailSet in interface java.util.NavigableSet<C extends java.lang.Comparable>tailSet in class ImmutableSortedSet<C extends java.lang.Comparable>abstract ContiguousSet<C> headSetImpl(C toElement, boolean inclusive)
headSetImpl in class ImmutableSortedSet<C extends java.lang.Comparable>abstract ContiguousSet<C> subSetImpl(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)
subSetImpl in class ImmutableSortedSet<C extends java.lang.Comparable>abstract ContiguousSet<C> tailSetImpl(C fromElement, boolean inclusive)
tailSetImpl in class ImmutableSortedSet<C extends java.lang.Comparable>public abstract ContiguousSet<C> intersection(ContiguousSet<C> other)
This method should always be used instead of Sets.intersection(java.util.Set<E>, java.util.Set<?>) for ContiguousSet instances.
public abstract Range<C> range()
range(CLOSED, CLOSED).java.util.NoSuchElementException - if this set is emptypublic abstract Range<C> range(BoundType lowerBoundType, BoundType upperBoundType)
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..∞).
java.util.NoSuchElementException - if this set is emptyImmutableSortedSet<C> createDescendingSet()
createDescendingSet in class ImmutableSortedSet<C extends java.lang.Comparable>public java.lang.String toString()
"[1..100]".toString in class java.util.AbstractCollection<C extends java.lang.Comparable>@Deprecated public static <E> ImmutableSortedSet.Builder<E> builder()
create(com.google.common.collect.Range<C>, com.google.common.collect.DiscreteDomain<C>).ContiguousSet instances are constructed with create(com.google.common.collect.Range<C>, com.google.common.collect.DiscreteDomain<C>). This
method exists only to hide ImmutableSet.builder() from consumers of ContiguousSet.java.lang.UnsupportedOperationException - always