Top Description Fields Constructors Methods
com.google.common.collect

public abstract Class ContiguousSet<C extends java.lang.Comparable<T>>

extends ImmutableSortedSet<C extends Comparable<T>>
Class Inheritance
Known Direct Subclasses
com.google.common.collect.EmptyContiguousSet, com.google.common.collect.RegularContiguousSet
Annotations
@GwtCompatible
emulated:true
@SuppressWarnings:rawtypes
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, java.util.Objects.requireNonNull

A sorted set of contiguous values in a given 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) can cause major performance problems.

Author
Gregory Kick
Since
10.0

Field Summary

Modifier and TypeField and Description
pack-priv final DiscreteDomain<C>
Inherited from com.google.common.collect.ImmutableSortedSet:
comparatordescendingSetSPLITERATOR_CHARACTERISTICS

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static <E> ImmutableSortedSet.Builder<E>
public static ContiguousSet<Integer>
closed(int lower, int upper)

Returns a nonempty contiguous set containing all int values from lower (inclusive) to upper (inclusive).

public static ContiguousSet<Long>
closed(long lower, long upper)

Returns a nonempty contiguous set containing all long values from lower (inclusive) to upper (inclusive).

public static ContiguousSet<Integer>
closedOpen(int lower, int upper)

Returns a contiguous set containing all int values from lower (inclusive) to upper (exclusive).

public static ContiguousSet<Long>
closedOpen(long lower, long upper)

Returns a contiguous set containing all long values from lower (inclusive) to upper (exclusive).

public static <C extends Comparable<T>> ContiguousSet<C>
create(Range<C> range, DiscreteDomain<C> domain)

Returns a ContiguousSet containing the same values in the given domain contained by the range.

pack-priv ImmutableSortedSet<C>
public ContiguousSet<C>
headSet(C
high endpoint (exclusive) of the returned set
toElement
)

Overrides com.google.common.collect.ImmutableSortedSet.headSet.

Implements java.util.NavigableSet.headSet.

Returns a view of the portion of this set whose elements are strictly less than toElement.
public ContiguousSet<C>
headSet(C
high endpoint of the returned set
toElement
,
boolean
true if the high endpoint is to be included in the returned view
inclusive
)

Overrides com.google.common.collect.ImmutableSortedSet.headSet.

Implements java.util.NavigableSet.headSet.

Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.
pack-priv abstract ContiguousSet<C>
headSetImpl(C toElement, boolean inclusive)

Implements abstract com.google.common.collect.ImmutableSortedSet.headSetImpl.

public abstract ContiguousSet<C>
intersection(ContiguousSet<C> other)

Returns the set of values that are contained in both this set and the other.

public abstract Range<C>
range()

Returns a range, closed on both ends, whose endpoints are the minimum and maximum values contained in this set.

public 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.

public ContiguousSet<C>
subSet(C
low endpoint (inclusive) of the returned set
fromElement
,
C
high endpoint (exclusive) of the returned set
toElement
)

Overrides com.google.common.collect.ImmutableSortedSet.subSet.

Implements java.util.NavigableSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
public ContiguousSet<C>
subSet(C
low endpoint of the returned set
fromElement
,
boolean
true if the low endpoint is to be included in the returned view
fromInclusive
,
C
high endpoint of the returned set
toElement
,
boolean
true if the high endpoint is to be included in the returned view
toInclusive
)

Overrides com.google.common.collect.ImmutableSortedSet.subSet.

Implements java.util.NavigableSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement to toElement.
pack-priv abstract ContiguousSet<C>
subSetImpl(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)

Implements abstract com.google.common.collect.ImmutableSortedSet.subSetImpl.

public ContiguousSet<C>
tailSet(C
low endpoint (inclusive) of the returned set
fromElement
)

Overrides com.google.common.collect.ImmutableSortedSet.tailSet.

Implements java.util.NavigableSet.tailSet.

Returns a view of the portion of this set whose elements are greater than or equal to fromElement.
public ContiguousSet<C>
tailSet(C
low endpoint of the returned set
fromElement
,
boolean
true if the low endpoint is to be included in the returned view
inclusive
)

Overrides com.google.common.collect.ImmutableSortedSet.tailSet.

Implements java.util.NavigableSet.tailSet.

Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.
pack-priv abstract ContiguousSet<C>
tailSetImpl(C fromElement, boolean inclusive)

Implements abstract com.google.common.collect.ImmutableSortedSet.tailSetImpl.

public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a shorthand representation of the contents such as "[1..100]".
Inherited from com.google.common.collect.ImmutableSortedSet:
ceilingcomparatorconstructcopyOfcopyOfcopyOfcopyOfcopyOfcopyOfcopyOfcopyOfSorteddescendingIteratordescendingSetemptySetfirstfloorhigherindexOfiteratorlastlowernaturalOrderofofofofofofoforderedBypollFirstpollLastreverseOrderspliteratortoImmutableSortedSetunsafeCompareunsafeComparewriteReplace

Field Detail

domainback to summary
pack-priv final DiscreteDomain<C> domain

Constructor Detail

ContiguousSetback to summary
pack-priv ContiguousSet(DiscreteDomain<C> domain)

Method Detail

builderback to summary
public static <E> ImmutableSortedSet.Builder<E> builder()

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.builder.

Deprecated

Use create.

Not supported. ContiguousSet instances are constructed with create. This method exists only to hide ImmutableSet#builder from consumers of ContiguousSet.

Annotations
@Deprecated
@DoNotCall:Always throws UnsupportedOperationException
Exceptions
UnsupportedOperationException:
always
closedback to summary
public static ContiguousSet<Integer> closed(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).)

Exceptions
IllegalArgumentException:
if lower is greater than upper
Since
23.0
closedback to summary
public static ContiguousSet<Long> closed(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).)

Exceptions
IllegalArgumentException:
if lower is greater than upper
Since
23.0
closedOpenback to summary
public static ContiguousSet<Integer> closedOpen(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).)

Exceptions
IllegalArgumentException:
if lower is greater than upper
Since
23.0
closedOpenback to summary
public static ContiguousSet<Long> closedOpen(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).)

Exceptions
IllegalArgumentException:
if lower is greater than upper
Since
23.0
createback to summary
public static <C extends Comparable<T>> ContiguousSet<C> create(Range<C> range, DiscreteDomain<C> domain)

Returns a ContiguousSet containing the same values in the given domain contained by the range.

Exceptions
IllegalArgumentException:
if neither range nor the domain has a lower bound, or if neither has an upper bound
Since
13.0
createDescendingSetback to summary
pack-priv ImmutableSortedSet<C> createDescendingSet()

Implements abstract com.google.common.collect.ImmutableSortedSet.createDescendingSet.

Annotations
@Override
@GwtIncompatible
headSetback to summary
public ContiguousSet<C> headSet(C toElement)

Overrides com.google.common.collect.ImmutableSortedSet.headSet.

Implements java.util.NavigableSet.headSet.

Doc from com.google.common.collect.ImmutableSortedSet.headSet.

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 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.

Parameters
toElement:C

Doc from java.util.SortedSet.headSet.

high endpoint (exclusive) of the returned set

Returns:ContiguousSet<C>

Doc from java.util.SortedSet.headSet.

a view of the portion of this set whose elements are strictly less than toElement

Annotations
@Override
headSetback to summary
public ContiguousSet<C> headSet(C toElement, boolean inclusive)

Overrides com.google.common.collect.ImmutableSortedSet.headSet.

Implements java.util.NavigableSet.headSet.

Doc from java.util.NavigableSet.headSet.

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.

Parameters
toElement:C

high endpoint of the returned set

inclusive:boolean

true if the high endpoint is to be included in the returned view

Returns:ContiguousSet<C>

a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement

Annotations
@GwtIncompatible
@Override
Since
12.0
headSetImplback to summary
pack-priv abstract ContiguousSet<C> headSetImpl(C toElement, boolean inclusive)

Implements abstract com.google.common.collect.ImmutableSortedSet.headSetImpl.

Annotations
@SuppressWarnings:MissingOverride
intersectionback to summary
public 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 for ContiguousSet instances.

rangeback to summary
public 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 to range(CLOSED, CLOSED).

Exceptions
NoSuchElementException:
if this set is empty
rangeback to summary
public 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#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..∞).

Exceptions
NoSuchElementException:
if this set is empty
subSetback to summary
public ContiguousSet<C> subSet(C fromElement, C toElement)

Overrides com.google.common.collect.ImmutableSortedSet.subSet.

Implements java.util.NavigableSet.subSet.

Doc from com.google.common.collect.ImmutableSortedSet.subSet.

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 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.

Parameters
fromElement:C

Doc from java.util.SortedSet.subSet.

low endpoint (inclusive) of the returned set

toElement:C

Doc from java.util.SortedSet.subSet.

high endpoint (exclusive) of the returned set

Returns:ContiguousSet<C>

Doc from java.util.SortedSet.subSet.

a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive

Annotations
@Override
subSetback to summary
public ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)

Overrides com.google.common.collect.ImmutableSortedSet.subSet.

Implements java.util.NavigableSet.subSet.

Doc from java.util.NavigableSet.subSet.

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.

Parameters
fromElement:C

low endpoint of the returned set

fromInclusive:boolean

true if the low endpoint is to be included in the returned view

toElement:C

high endpoint of the returned set

toInclusive:boolean

true if the high endpoint is to be included in the returned view

Returns:ContiguousSet<C>

a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive

Annotations
@GwtIncompatible
@Override
Since
12.0
subSetImplback to summary
pack-priv abstract ContiguousSet<C> subSetImpl(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)

Implements abstract com.google.common.collect.ImmutableSortedSet.subSetImpl.

Annotations
@SuppressWarnings:MissingOverride
tailSetback to summary
public ContiguousSet<C> tailSet(C fromElement)

Overrides com.google.common.collect.ImmutableSortedSet.tailSet.

Implements java.util.NavigableSet.tailSet.

Doc from com.google.common.collect.ImmutableSortedSet.tailSet.

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 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.

Parameters
fromElement:C

Doc from java.util.SortedSet.tailSet.

low endpoint (inclusive) of the returned set

Returns:ContiguousSet<C>

Doc from java.util.SortedSet.tailSet.

a view of the portion of this set whose elements are greater than or equal to fromElement

Annotations
@Override
tailSetback to summary
public ContiguousSet<C> tailSet(C fromElement, boolean inclusive)

Overrides com.google.common.collect.ImmutableSortedSet.tailSet.

Implements java.util.NavigableSet.tailSet.

Doc from java.util.NavigableSet.tailSet.

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.

Parameters
fromElement:C

low endpoint of the returned set

inclusive:boolean

true if the low endpoint is to be included in the returned view

Returns:ContiguousSet<C>

a view of the portion of this set whose elements are greater than or equal to fromElement

Annotations
@GwtIncompatible
@Override
Since
12.0
tailSetImplback to summary
pack-priv abstract ContiguousSet<C> tailSetImpl(C fromElement, boolean inclusive)

Implements abstract com.google.common.collect.ImmutableSortedSet.tailSetImpl.

Annotations
@SuppressWarnings:MissingOverride
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Returns a shorthand representation of the contents such as "[1..100]".

Returns:String

Doc from java.util.AbstractCollection.toString.

a string representation of this collection

Annotations
@Override