public interface IntRangeSet
C
.
Implementations that choose to support the add(IntRange)
operation are required to
ignore empty ranges and coalesce connected ranges. For example:
<p>
IntRangeSet rangeSet = IntTreeRangeSet.createFromCsv();
rangeSet.add(IntRange.closed(1, 10)); // {[1, 10]}
rangeSet.add(IntRange.closedOpen(11, 15)); // disconnected range; {[1, 10], [11, 15)}
rangeSet.add(IntRange.closedOpen(15, 20)); // connected range; {[1, 10], [11, 20)}
rangeSet.add(IntRange.openClosed(0, 0)); // empty range; {[1, 10], [11, 20)}
rangeSet.remove(IntRange.open(5, 10)); // splits [1, 10]; {[1, 5], [10, 10], [11, 20)}
Note that the behavior of IntRange.isEmpty()
and IntRange.isConnected(IntRange)
may
not be as expected on discrete ranges. See the Javadoc of those methods for details.
Modifier and Type | Method and Description |
---|---|
void |
add(IntRange range)
Adds the specified range to this
IntRangeSet (optional operation). |
void |
addAll(IntRangeSet other)
Adds all of the ranges from the specified range set to this range set (optional operation).
|
Set<IntRange> |
asRanges()
Returns a view of the disconnected ranges that make up this
range set.
|
void |
clear()
Removes all ranges from this
IntRangeSet (optional operation). |
IntRangeSet |
complement()
Returns a view of the complement of this
IntRangeSet . |
boolean |
contains(int value)
Determines whether any of this range set's member ranges contains
value . |
boolean |
encloses(IntRange otherRange)
Returns
true if there exists a member range in this range set which
encloses the specified range. |
boolean |
enclosesAll(IntRangeSet 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 IntRangeSet that contains the same ranges
according to IntRange.equals(Object) . |
int |
hashCode()
Returns
asRanges().hashCode() . |
boolean |
intersects(IntRange otherRange)
Returns
true if there exists a non-empty range enclosed by both a member range in this
range set and the specified range. |
boolean |
isEmpty()
Returns
true if this range set contains no ranges. |
IntRange |
rangeContaining(int value)
Returns the unique range from this range set that contains
value , or null if this range set does not contain value . |
void |
remove(IntRange range)
Removes the specified range from this
IntRangeSet (optional operation). |
void |
removeAll(IntRangeSet other)
Removes all of the ranges from the specified range set from this range set (optional
operation).
|
IntRange |
span()
Returns the minimal range which encloses all ranges
in this range set.
|
IntRangeSet |
subRangeSet(IntRange view)
Returns a view of the intersection of this
IntRangeSet with the specified range. |
String |
toString()
Returns a readable string representation of this range set.
|
boolean contains(int value)
value
.IntRange rangeContaining(int value)
value
, or null
if this range set does not contain value
.boolean intersects(IntRange otherRange)
true
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 calling
subRangeSet(otherRange)
and testing whether the resulting range set is non-empty.boolean encloses(IntRange otherRange)
true
if there exists a member range in this range set which
encloses the specified range.boolean enclosesAll(IntRangeSet 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(tech.tablesaw.util.collections.IntRange)
each of the ranges in
other
.
boolean isEmpty()
true
if this range set contains no ranges.IntRange span()
NoSuchElementException
- if this range set is emptySet<IntRange> asRanges()
Iterable.iterator()
method return the ranges in increasing order of lower bound
(equivalently, of upper bound).IntRangeSet complement()
IntRangeSet
.
The returned view supports the add(tech.tablesaw.util.collections.IntRange)
operation if this IntRangeSet
supports
remove(tech.tablesaw.util.collections.IntRange)
, and vice versa.
IntRangeSet subRangeSet(IntRange view)
IntRangeSet
with the specified range.
The returned view supports all optional operations supported by this IntRangeSet
, with
the caveat that an IllegalArgumentException
is thrown on an attempt to
add any range not enclosed by
view
.
void add(IntRange range)
IntRangeSet
(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(IntRange range)
IntRangeSet
(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()
IntRangeSet
(optional operation). After this operation,
this.contains(c)
will return false for all c
.
This is equivalent to remove(IntRange.all())
.
UnsupportedOperationException
- if this range set does not support the clear
operationvoid addAll(IntRangeSet other)
other
.
This is equivalent to calling add(tech.tablesaw.util.collections.IntRange)
on each of the ranges in other
in turn.
UnsupportedOperationException
- if this range set does not support the addAll
operationvoid removeAll(IntRangeSet other)
other.contains(c)
, this.contains(c)
will
return false
.
This is equivalent to calling remove(tech.tablesaw.util.collections.IntRange)
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 IntRangeSet
that contains the same ranges
according to IntRange.equals(Object)
.Copyright © 2017. All rights reserved.