Package com.google.common.collect
Class TreeRangeSet<C extends java.lang.Comparable<?>>
- java.lang.Object
-
- com.google.common.collect.AbstractRangeSet<C>
-
- com.google.common.collect.TreeRangeSet<C>
-
- All Implemented Interfaces:
RangeSet<C>
,java.io.Serializable
- Direct Known Subclasses:
TreeRangeSet.Complement
,TreeRangeSet.SubRangeSet
public class TreeRangeSet<C extends java.lang.Comparable<?>> extends AbstractRangeSet<C> implements java.io.Serializable
An implementation ofRangeSet
backed by aTreeMap
.- Since:
- 14.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
TreeRangeSet.AsRanges
private class
TreeRangeSet.Complement
private static class
TreeRangeSet.ComplementRangesByLowerBound<C extends java.lang.Comparable<?>>
(package private) static class
TreeRangeSet.RangesByUpperBound<C extends java.lang.Comparable<?>>
private class
TreeRangeSet.SubRangeSet
private static class
TreeRangeSet.SubRangeSetRangesByLowerBound<C extends java.lang.Comparable<?>>
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<Range<C>>
asDescendingSetOfRanges
private java.util.Set<Range<C>>
asRanges
private RangeSet<C>
complement
(package private) java.util.NavigableMap<Cut<C>,Range<C>>
rangesByLowerBound
-
Constructor Summary
Constructors Modifier Constructor Description private
TreeRangeSet(java.util.NavigableMap<Cut<C>,Range<C>> rangesByLowerCut)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Range<C> rangeToAdd)
Adds the specified range to thisRangeSet
(optional operation).java.util.Set<Range<C>>
asDescendingSetOfRanges()
Returns a descending view of the disconnected ranges that make up this range set.java.util.Set<Range<C>>
asRanges()
Returns a view of the disconnected ranges that make up this range set.RangeSet<C>
complement()
Returns a view of the complement of thisRangeSet
.static <C extends java.lang.Comparable<?>>
TreeRangeSet<C>create()
Creates an emptyTreeRangeSet
instance.static <C extends java.lang.Comparable<?>>
TreeRangeSet<C>create(RangeSet<C> rangeSet)
Returns aTreeRangeSet
initialized with the ranges in the specified range set.static <C extends java.lang.Comparable<?>>
TreeRangeSet<C>create(java.lang.Iterable<Range<C>> ranges)
Returns aTreeRangeSet
representing the union of the specified ranges.boolean
encloses(Range<C> range)
Returnstrue
if there exists a member range in this range set which encloses the specified range.boolean
intersects(Range<C> range)
Returnstrue
if there exists a non-empty range enclosed by both a member range in this range set and the specified range.Range<C>
rangeContaining(C value)
Returns the unique range from this range set that containsvalue
, ornull
if this range set does not containvalue
.private Range<C>
rangeEnclosing(Range<C> range)
void
remove(Range<C> rangeToRemove)
Removes the specified range from thisRangeSet
(optional operation).private void
replaceRangeWithSameLowerBound(Range<C> range)
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 thisRangeSet
with the specified range.-
Methods inherited from class com.google.common.collect.AbstractRangeSet
addAll, clear, contains, enclosesAll, equals, hashCode, isEmpty, removeAll, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.collect.RangeSet
addAll, enclosesAll, removeAll
-
-
-
-
Field Detail
-
rangesByLowerBound
final java.util.NavigableMap<Cut<C extends java.lang.Comparable<?>>,Range<C extends java.lang.Comparable<?>>> rangesByLowerBound
-
asRanges
@CheckForNull private transient java.util.Set<Range<C extends java.lang.Comparable<?>>> asRanges
-
asDescendingSetOfRanges
@CheckForNull private transient java.util.Set<Range<C extends java.lang.Comparable<?>>> asDescendingSetOfRanges
-
-
Method Detail
-
create
public static <C extends java.lang.Comparable<?>> TreeRangeSet<C> create()
Creates an emptyTreeRangeSet
instance.
-
create
public static <C extends java.lang.Comparable<?>> TreeRangeSet<C> create(RangeSet<C> rangeSet)
Returns aTreeRangeSet
initialized with the ranges in the specified range set.
-
create
public static <C extends java.lang.Comparable<?>> TreeRangeSet<C> create(java.lang.Iterable<Range<C>> ranges)
Returns aTreeRangeSet
representing the union of the specified ranges.This is the smallest
RangeSet
which encloses each of the specified ranges. An element will be contained in thisRangeSet
if and only if it is contained in at least oneRange
inranges
.- Since:
- 21.0
-
asRanges
public java.util.Set<Range<C>> asRanges()
Description copied from interface:RangeSet
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).
-
asDescendingSetOfRanges
public java.util.Set<Range<C>> asDescendingSetOfRanges()
Description copied from interface:RangeSet
Returns a descending 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 decreasing order of lower bound (equivalently, of upper bound).- Specified by:
asDescendingSetOfRanges
in interfaceRangeSet<C extends java.lang.Comparable<?>>
-
rangeContaining
@CheckForNull public Range<C> rangeContaining(C value)
Description copied from interface:RangeSet
Returns the unique range from this range set that containsvalue
, ornull
if this range set does not containvalue
.- Specified by:
rangeContaining
in interfaceRangeSet<C extends java.lang.Comparable<?>>
- Specified by:
rangeContaining
in classAbstractRangeSet<C extends java.lang.Comparable<?>>
-
intersects
public boolean intersects(Range<C> range)
Description copied from interface:RangeSet
Returnstrue
if there exists a non-empty range enclosed by both a member range in this range set and the specified range. This is equivalent to callingsubRangeSet(otherRange)
and testing whether the resulting range set is non-empty.- Specified by:
intersects
in interfaceRangeSet<C extends java.lang.Comparable<?>>
- Overrides:
intersects
in classAbstractRangeSet<C extends java.lang.Comparable<?>>
-
encloses
public boolean encloses(Range<C> range)
Description copied from interface:RangeSet
Returnstrue
if there exists a member range in this range set which encloses the specified range.
-
span
public Range<C> span()
Description copied from interface:RangeSet
Returns the minimal range which encloses all ranges in this range set.
-
add
public void add(Range<C> rangeToAdd)
Description copied from interface:RangeSet
Adds the specified range to thisRangeSet
(optional operation). That is, for equal range sets a and b, the result ofa.add(range)
is thata
will be the minimal range set for which botha.enclosesAll(b)
anda.encloses(range)
.Note that
range
will be coalesced with any ranges in the range set that are connected with it. Moreover, ifrange
is empty, this is a no-op.
-
remove
public void remove(Range<C> rangeToRemove)
Description copied from interface:RangeSet
Removes the specified range from thisRangeSet
(optional operation). After this operation, ifrange.contains(c)
,this.contains(c)
will returnfalse
.If
range
is empty, this is a no-op.
-
complement
public RangeSet<C> complement()
Description copied from interface:RangeSet
Returns a view of the complement of thisRangeSet
.The returned view supports the
RangeSet.add(com.google.common.collect.Range<C>)
operation if thisRangeSet
supportsRangeSet.remove(com.google.common.collect.Range<C>)
, and vice versa.- Specified by:
complement
in interfaceRangeSet<C extends java.lang.Comparable<?>>
-
subRangeSet
public RangeSet<C> subRangeSet(Range<C> view)
Description copied from interface:RangeSet
Returns a view of the intersection of thisRangeSet
with the specified range.The returned view supports all optional operations supported by this
RangeSet
, with the caveat that anIllegalArgumentException
is thrown on an attempt to add any range not enclosed byview
.- Specified by:
subRangeSet
in interfaceRangeSet<C extends java.lang.Comparable<?>>
-
-