@Beta @GwtCompatible(emulated=true) public abstract class ContiguousSet<C extends Comparable> extends ImmutableSortedSet<C>
DiscreteDomain
.
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>
Modifier and Type | Method and Description |
---|---|
static <E> ImmutableSortedSet.Builder<E> |
builder()
|
static <C extends Comparable> |
create(Range<C> range,
DiscreteDomain<C> domain)
Returns a
ContiguousSet containing 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 than toElement.
|
ContiguousSet<C> |
headSet(C toElement,
boolean inclusive)
Returns a view of the portion of this set whose elements are less than
(or equal to, if
inclusive is true) toElement . |
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)
Returns a view of the portion of this set whose elements range from
fromElement to toElement . |
ContiguousSet<C> |
subSet(C fromElement,
C toElement)
Returns a view of the portion of this set whose elements range
from fromElement, inclusive, to toElement,
exclusive.
|
ContiguousSet<C> |
tailSet(C fromElement)
Returns a view of the portion of this set whose elements are
greater than or equal to fromElement.
|
ContiguousSet<C> |
tailSet(C fromElement,
boolean inclusive)
Returns a view of the portion of this set whose elements are greater
than (or equal to, if
inclusive is true) fromElement . |
String |
toString()
Returns a short-hand representation of the contents such as
"[1..100]" . |
ceiling, 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
equals, hashCode
add, addAll, asList, clear, contains, remove, removeAll, retainAll, toArray, toArray
containsAll, isEmpty, size
public static <C extends Comparable> ContiguousSet<C> create(Range<C> range, DiscreteDomain<C> domain)
ContiguousSet
containing the same values in the given domain
contained by the range.IllegalArgumentException
- if neither range nor the domain has a lower bound, or if
neither has an upper boundpublic ContiguousSet<C> headSet(C toElement)
ImmutableSortedSet
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
.
headSet
in interface NavigableSet<C extends Comparable>
headSet
in interface SortedSet<C extends Comparable>
headSet
in class ImmutableSortedSet<C extends Comparable>
toElement
- high endpoint (exclusive) of the returned set@GwtIncompatible(value="NavigableSet") public ContiguousSet<C> headSet(C toElement, boolean inclusive)
java.util.NavigableSet
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.
headSet
in interface NavigableSet<C extends Comparable>
headSet
in class ImmutableSortedSet<C extends Comparable>
toElement
- high endpoint of the returned setinclusive
- true
if the high endpoint
is to be included in the returned viewinclusive
is true) toElement
public ContiguousSet<C> subSet(C fromElement, C toElement)
ImmutableSortedSet
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
.
subSet
in interface NavigableSet<C extends Comparable>
subSet
in interface SortedSet<C extends Comparable>
subSet
in class ImmutableSortedSet<C extends Comparable>
fromElement
- low endpoint (inclusive) of the returned settoElement
- high endpoint (exclusive) of the returned set@GwtIncompatible(value="NavigableSet") public ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)
java.util.NavigableSet
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.
subSet
in interface NavigableSet<C extends Comparable>
subSet
in class ImmutableSortedSet<C extends Comparable>
fromElement
- low endpoint of the returned setfromInclusive
- true
if the low endpoint
is to be included in the returned viewtoElement
- high endpoint of the returned settoInclusive
- true
if the high endpoint
is to be included in the returned viewfromElement
, inclusive, to toElement
, exclusivepublic ContiguousSet<C> tailSet(C fromElement)
ImmutableSortedSet
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
.
tailSet
in interface NavigableSet<C extends Comparable>
tailSet
in interface SortedSet<C extends Comparable>
tailSet
in class ImmutableSortedSet<C extends Comparable>
fromElement
- low endpoint (inclusive) of the returned set@GwtIncompatible(value="NavigableSet") public ContiguousSet<C> tailSet(C fromElement, boolean inclusive)
java.util.NavigableSet
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.
tailSet
in interface NavigableSet<C extends Comparable>
tailSet
in class ImmutableSortedSet<C extends Comparable>
fromElement
- low endpoint of the returned setinclusive
- true
if the low endpoint
is to be included in the returned viewfromElement
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)
.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..∞)
.
NoSuchElementException
- if this set is emptypublic String toString()
"[1..100]"
.toString
in class AbstractCollection<C extends 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
.UnsupportedOperationException
- alwaysCopyright © 2010-2014. All Rights Reserved.