@Beta public interface RangeSet<C extends Comparable>
C
.
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()
and Range.isConnected(Range)
may
not be as expected on discrete ranges. See the Javadoc of those methods for details.
For a Set
whose contents are specified by a Range
, see ContiguousSet
.
Modifier and Type | Method and Description |
---|---|
void |
add(Range<C> range)
Adds the specified range to this
RangeSet (optional operation). |
void |
addAll(RangeSet<C> other)
Adds all of the ranges from the specified range set to this range set (optional operation).
|
Set<Range<C>> |
asRanges()
Returns a view of the disconnected ranges that make up this
range set.
|
void |
clear()
Removes all ranges from this
RangeSet (optional operation). |
RangeSet<C> |
complement()
Returns a view of the complement of this
RangeSet . |
boolean |
contains(C value)
Determines whether any of this range set's member ranges contains
value . |
boolean |
encloses(Range<C> otherRange)
Returns
true if there exists a member range in this range set which
encloses the specified range. |
boolean |
enclosesAll(RangeSet<C> other)
Returns
true if for each member range in other there exists a member range in
this range set which encloses it. |
boolean |
equals(Object obj)
Returns
true if obj is another RangeSet that contains the same ranges
according to Range.equals(Object) . |
int |
hashCode()
Returns
asRanges().hashCode() . |
boolean |
isEmpty()
Returns
true if this range set contains no ranges. |
Range<C> |
rangeContaining(C value)
Returns the unique range from this range set that contains
value , or null if this range set does not contain value . |
void |
remove(Range<C> range)
Removes the specified range from this
RangeSet (optional operation). |
void |
removeAll(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 this
RangeSet with the specified range. |
String |
toString()
Returns a readable string representation of this range set.
|
boolean contains(C value)
value
.Range<C> rangeContaining(C value)
value
, or null
if this range set does not contain value
.boolean encloses(Range<C> otherRange)
true
if there exists a member range in this range set which
encloses the specified range.boolean enclosesAll(RangeSet<C> other)
true
if for each member range in other
there exists a member range in
this range set which encloses it. It follows that
this.contains(value)
whenever other.contains(value)
. Returns true
if
other
is empty.
This is equivalent to checking if this range set encloses(com.google.common.collect.Range<C>)
each of the ranges in
other
.
boolean isEmpty()
true
if this range set contains no ranges.Range<C> span()
NoSuchElementException
- if this range set is emptySet<Range<C>> asRanges()
Iterable.iterator()
method return the ranges in increasing order of lower bound
(equivalently, of upper bound).RangeSet<C> complement()
RangeSet
.
The returned view supports the add(com.google.common.collect.Range<C>)
operation if this RangeSet
supports
remove(com.google.common.collect.Range<C>)
, and vice versa.
RangeSet<C> subRangeSet(Range<C> view)
RangeSet
with the specified range.
The returned view supports all optional operations supported by this RangeSet
, with
the caveat that an IllegalArgumentException
is thrown on an attempt to
add any range not enclosed by
view
.
void add(Range<C> range)
RangeSet
(optional operation). That is, for equal
range sets a and b, the result of a.add(range)
is that a
will be the minimal
range set for which both a.enclosesAll(b)
and a.encloses(range)
.
Note that range
will be coalesced with any ranges in
the range set that are connected with it. Moreover,
if range
is empty, this is a no-op.
UnsupportedOperationException
- if this range set does not support the add
operationvoid remove(Range<C> range)
RangeSet
(optional operation). After this
operation, if range.contains(c)
, this.contains(c)
will return false
.
If range
is empty, this is a no-op.
UnsupportedOperationException
- if this range set does not support the remove
operationvoid clear()
RangeSet
(optional operation). After this operation,
this.contains(c)
will return false for all c
.
This is equivalent to remove(Range.all())
.
UnsupportedOperationException
- if this range set does not support the clear
operationvoid addAll(RangeSet<C> other)
other
.
This is equivalent to calling add(com.google.common.collect.Range<C>)
on each of the ranges in other
in turn.
UnsupportedOperationException
- if this range set does not support the addAll
operationvoid removeAll(RangeSet<C> other)
other.contains(c)
, this.contains(c)
will
return false
.
This is equivalent to calling remove(com.google.common.collect.Range<C>)
on each of the ranges in other
in
turn.
UnsupportedOperationException
- if this range set does not support the removeAll
operationboolean equals(@Nullable Object obj)
true
if obj
is another RangeSet
that contains the same ranges
according to Range.equals(Object)
.Copyright © 2010-2013. All Rights Reserved.