Interface RangeSet<C extends java.lang.Comparable>
- 
- All Known Implementing Classes:
 ImmutableRangeSet,TreeRangeSet
@Beta public interface RangeSet<C extends java.lang.Comparable>
A set comprising zero or more nonempty, disconnected ranges of typeC.Implementations that choose to support the
add(Range)operation are required to ignore empty ranges and coalesce connected ranges. For example:RangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(1, 10)); // {[1, 10]} rangeSet.add(Range.closedOpen(11, 15)); // {[1, 10], [11, 15)} rangeSet.add(Range.open(15, 20)); // disconnected range; {[1, 10], [11, 20)} rangeSet.add(Range.openClosed(0, 0)); // empty range; {[1, 10], [11, 20)} rangeSet.remove(Range.open(5, 10)); // splits [1, 10]; {[1, 5], [10, 10], [11, 20)}Note that the behavior of
Range.isEmpty()andRange.isConnected(Range)may not be as expected on discrete ranges. See the Javadoc of those methods for details.For a
Setwhose contents are specified by aRange, seeContiguousSet.- Since:
 - 14.0
 
 
- 
- 
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(Range<C> range)Adds the specified range to thisRangeSet(optional operation).voidaddAll(RangeSet<C> other)Adds all of the ranges from the specified range set to this range set (optional operation).java.util.Set<Range<C>>asRanges()Returns a view of the disconnected ranges that make up this range set.voidclear()Removes all ranges from thisRangeSet(optional operation).RangeSet<C>complement()Returns a view of the complement of thisRangeSet.booleancontains(C value)Determines whether any of this range set's member ranges containsvalue.booleanencloses(Range<C> otherRange)Returnstrueif there exists a member range in this range set which encloses the specified range.booleanenclosesAll(RangeSet<C> other)Returnstrueif for each member range inotherthere exists a member range in this range set which encloses it.booleanequals(java.lang.Object obj)Returnstrueifobjis anotherRangeSetthat contains the same ranges according toRange.equals(Object).inthashCode()ReturnsasRanges().hashCode().booleanisEmpty()Returnstrueif this range set contains no ranges.Range<C>rangeContaining(C value)Returns the unique range from this range set that containsvalue, ornullif this range set does not containvalue.voidremove(Range<C> range)Removes the specified range from thisRangeSet(optional operation).voidremoveAll(RangeSet<C> other)Removes all of the ranges from the specified range set from this range set (optional operation).Range<C>span()Returns the minimal range which encloses all ranges in this range set.RangeSet<C>subRangeSet(Range<C> view)Returns a view of the intersection of thisRangeSetwith the specified range.java.lang.StringtoString()Returns a readable string representation of this range set. 
 - 
 
- 
- 
Method Detail
- 
contains
boolean contains(C value)
Determines whether any of this range set's member ranges containsvalue. 
- 
rangeContaining
Range<C> rangeContaining(C value)
Returns the unique range from this range set that containsvalue, ornullif this range set does not containvalue. 
- 
encloses
boolean encloses(Range<C> otherRange)
Returnstrueif there exists a member range in this range set which encloses the specified range. 
- 
enclosesAll
boolean enclosesAll(RangeSet<C> other)
Returnstrueif for each member range inotherthere exists a member range in this range set which encloses it. It follows thatthis.contains(value)wheneverother.contains(value). Returnstrueifotheris empty.This is equivalent to checking if this range set
encloses(com.google.common.collect.Range<C>)each of the ranges inother. 
- 
isEmpty
boolean isEmpty()
Returnstrueif this range set contains no ranges. 
- 
span
Range<C> span()
Returns the minimal range which encloses all ranges in this range set.- Throws:
 java.util.NoSuchElementException- if this range set is empty
 
- 
asRanges
java.util.Set<Range<C>> asRanges()
Returns a view of the disconnected ranges that make up this range set. The returned set may be empty. The iterators returned by itsIterable.iterator()method return the ranges in increasing order of lower bound (equivalently, of upper bound). 
- 
complement
RangeSet<C> complement()
Returns a view of the complement of thisRangeSet.The returned view supports the
add(com.google.common.collect.Range<C>)operation if thisRangeSetsupportsremove(com.google.common.collect.Range<C>), and vice versa. 
- 
add
void add(Range<C> range)
Adds the specified range to thisRangeSet(optional operation). That is, for equal range sets a and b, the result ofa.add(range)is thatawill be the minimal range set for which botha.enclosesAll(b)anda.encloses(range).Note that
rangewill be coalesced with any ranges in the range set that are connected with it. Moreover, ifrangeis empty, this is a no-op.- Throws:
 java.lang.UnsupportedOperationException- if this range set does not support theaddoperation
 
- 
remove
void remove(Range<C> range)
Removes the specified range from thisRangeSet(optional operation). After this operation, ifrange.contains(c),this.contains(c)will returnfalse.If
rangeis empty, this is a no-op.- Throws:
 java.lang.UnsupportedOperationException- if this range set does not support theremoveoperation
 
- 
clear
void clear()
Removes all ranges from thisRangeSet(optional operation). After this operation,this.contains(c)will return false for allc.This is equivalent to
remove(Range.all()).- Throws:
 java.lang.UnsupportedOperationException- if this range set does not support theclearoperation
 
- 
addAll
void addAll(RangeSet<C> other)
Adds all of the ranges from the specified range set to this range set (optional operation). After this operation, this range set is the minimal range set that encloses both the original range set andother.This is equivalent to calling
add(com.google.common.collect.Range<C>)on each of the ranges inotherin turn.- Throws:
 java.lang.UnsupportedOperationException- if this range set does not support theaddAlloperation
 
- 
removeAll
void removeAll(RangeSet<C> other)
Removes all of the ranges from the specified range set from this range set (optional operation). After this operation, ifother.contains(c),this.contains(c)will returnfalse.This is equivalent to calling
remove(com.google.common.collect.Range<C>)on each of the ranges inotherin turn.- Throws:
 java.lang.UnsupportedOperationException- if this range set does not support theremoveAlloperation
 
- 
equals
boolean equals(@Nullable java.lang.Object obj)Returnstrueifobjis anotherRangeSetthat contains the same ranges according toRange.equals(Object).- Overrides:
 equalsin classjava.lang.Object
 
- 
hashCode
int hashCode()
ReturnsasRanges().hashCode().- Overrides:
 hashCodein classjava.lang.Object
 
- 
toString
java.lang.String toString()
Returns a readable string representation of this range set. For example, if thisRangeSetconsisted ofRange.closed(1, 3)andRange.greaterThan(4), this might return" [1‥3](4‥+∞)"}.- Overrides:
 toStringin classjava.lang.Object
 
 - 
 
 -