Class ContiguousSet<C extends java.lang.Comparable>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- com.google.common.collect.ImmutableCollection<E>
-
- com.google.common.collect.ImmutableSet<E>
-
- com.google.common.collect.ImmutableSortedSetFauxverideShim<E>
-
- com.google.common.collect.ImmutableSortedSet<C>
-
- com.google.common.collect.ContiguousSet<C>
-
- All Implemented Interfaces:
SortedIterable<C>,java.io.Serializable,java.lang.Iterable<C>,java.util.Collection<C>,java.util.NavigableSet<C>,java.util.Set<C>,java.util.SortedSet<C>
- Direct Known Subclasses:
EmptyContiguousSet,RegularContiguousSet
public abstract class ContiguousSet<C extends java.lang.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
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.collect.ImmutableSortedSet
ImmutableSortedSet.Builder<E>
-
Nested classes/interfaces inherited from class com.google.common.collect.ImmutableSet
ImmutableSet.Indexed<E>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) DiscreteDomain<C>domain-
Fields inherited from class com.google.common.collect.ImmutableSortedSet
comparator, descendingSet, SPLITERATOR_CHARACTERISTICS
-
Fields inherited from class com.google.common.collect.ImmutableSet
HASH_FLOODING_FPP, MAX_RUN_MULTIPLIER, MAX_TABLE_SIZE
-
-
Constructor Summary
Constructors Constructor Description ContiguousSet(DiscreteDomain<C> domain)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <E> ImmutableSortedSet.Builder<E>builder()static ContiguousSet<java.lang.Integer>closed(int lower, int upper)Returns a nonempty contiguous set containing allintvalues fromlower(inclusive) toupper(inclusive).static ContiguousSet<java.lang.Long>closed(long lower, long upper)Returns a nonempty contiguous set containing alllongvalues fromlower(inclusive) toupper(inclusive).static ContiguousSet<java.lang.Integer>closedOpen(int lower, int upper)Returns a contiguous set containing allintvalues fromlower(inclusive) toupper(exclusive).static ContiguousSet<java.lang.Long>closedOpen(long lower, long upper)Returns a contiguous set containing alllongvalues fromlower(inclusive) toupper(exclusive).static <C extends java.lang.Comparable>
ContiguousSet<C>create(Range<C> range, DiscreteDomain<C> domain)Returns aContiguousSetcontaining 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.StringtoString()Returns a short-hand representation of the contents such as"[1..100]".-
Methods inherited from class com.google.common.collect.ImmutableSortedSet
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, writeReplace
-
Methods inherited from class com.google.common.collect.ImmutableSortedSetFauxverideShim
builderWithExpectedSize, copyOf, of, of, of, of, of, of, toImmutableSet
-
Methods inherited from class com.google.common.collect.ImmutableSet
asList, chooseTableSize, createAsList, equals, hashCode, hashFloodingDetected, isHashCodeFast, rebuildHashTable
-
Methods inherited from class com.google.common.collect.ImmutableCollection
add, addAll, clear, contains, copyIntoArray, internalArray, internalArrayEnd, internalArrayStart, isPartialView, remove, removeAll, removeIf, retainAll, toArray, toArray
-
-
-
-
Field Detail
-
domain
final DiscreteDomain<C extends java.lang.Comparable> domain
-
-
Constructor Detail
-
ContiguousSet
ContiguousSet(DiscreteDomain<C> domain)
-
-
Method Detail
-
create
public static <C extends java.lang.Comparable> ContiguousSet<C> create(Range<C> range, DiscreteDomain<C> domain)
Returns aContiguousSetcontaining the same values in the given domain contained by the range.- Throws:
java.lang.IllegalArgumentException- if neither range nor the domain has a lower bound, or if neither has an upper bound- Since:
- 13.0
-
closed
public static ContiguousSet<java.lang.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:
java.lang.IllegalArgumentException- ifloweris greater thanupper- Since:
- 23.0
-
closed
public static ContiguousSet<java.lang.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:
java.lang.IllegalArgumentException- ifloweris greater thanupper- Since:
- 23.0
-
closedOpen
public static ContiguousSet<java.lang.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:
java.lang.IllegalArgumentException- ifloweris greater thanupper- Since:
- 23.0
-
closedOpen
public static ContiguousSet<java.lang.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:
java.lang.IllegalArgumentException- ifloweris greater thanupper- Since:
- 23.0
-
headSet
public ContiguousSet<C> headSet(C toElement)
Description 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 interfacejava.util.NavigableSet<C extends java.lang.Comparable>- Specified by:
headSetin interfacejava.util.SortedSet<C extends java.lang.Comparable>- Overrides:
headSetin classImmutableSortedSet<C extends java.lang.Comparable>
-
headSet
public ContiguousSet<C> headSet(C toElement, boolean inclusive)
- Specified by:
headSetin interfacejava.util.NavigableSet<C extends java.lang.Comparable>- Overrides:
headSetin classImmutableSortedSet<C extends java.lang.Comparable>- Since:
- 12.0
-
subSet
public ContiguousSet<C> subSet(C fromElement, C toElement)
Description 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 interfacejava.util.NavigableSet<C extends java.lang.Comparable>- Specified by:
subSetin interfacejava.util.SortedSet<C extends java.lang.Comparable>- Overrides:
subSetin classImmutableSortedSet<C extends java.lang.Comparable>
-
subSet
public ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)
- Specified by:
subSetin interfacejava.util.NavigableSet<C extends java.lang.Comparable>- Overrides:
subSetin classImmutableSortedSet<C extends java.lang.Comparable>- Since:
- 12.0
-
tailSet
public ContiguousSet<C> tailSet(C fromElement)
Description 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 interfacejava.util.NavigableSet<C extends java.lang.Comparable>- Specified by:
tailSetin interfacejava.util.SortedSet<C extends java.lang.Comparable>- Overrides:
tailSetin classImmutableSortedSet<C extends java.lang.Comparable>
-
tailSet
public ContiguousSet<C> tailSet(C fromElement, boolean inclusive)
- Specified by:
tailSetin interfacejava.util.NavigableSet<C extends java.lang.Comparable>- Overrides:
tailSetin classImmutableSortedSet<C extends java.lang.Comparable>- Since:
- 12.0
-
headSetImpl
abstract ContiguousSet<C> headSetImpl(C toElement, boolean inclusive)
- Specified by:
headSetImplin classImmutableSortedSet<C extends java.lang.Comparable>
-
subSetImpl
abstract ContiguousSet<C> subSetImpl(C fromElement, boolean fromInclusive, C toElement, boolean toInclusive)
- Specified by:
subSetImplin classImmutableSortedSet<C extends java.lang.Comparable>
-
tailSetImpl
abstract ContiguousSet<C> tailSetImpl(C fromElement, boolean inclusive)
- Specified by:
tailSetImplin classImmutableSortedSet<C extends java.lang.Comparable>
-
intersection
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(java.util.Set<E>, java.util.Set<?>)forContiguousSetinstances.
-
range
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 torange(CLOSED, CLOSED).- Throws:
java.util.NoSuchElementException- if this set is empty
-
range
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.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:
java.util.NoSuchElementException- if this set is empty
-
createDescendingSet
ImmutableSortedSet<C> createDescendingSet()
- Specified by:
createDescendingSetin classImmutableSortedSet<C extends java.lang.Comparable>
-
toString
public java.lang.String toString()
Returns a short-hand representation of the contents such as"[1..100]".- Overrides:
toStringin classjava.util.AbstractCollection<C extends java.lang.Comparable>
-
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:
java.lang.UnsupportedOperationException- always
-
-