public final class IntRange
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static IntRange |
all()
Returns a range that contains every value of type
int . |
static IntRange |
atLeast(int endpoint)
Returns a range that contains all values greater than or equal to
endpoint . |
static IntRange |
atMost(int endpoint)
Returns a range that contains all values less than or equal to
endpoint . |
IntRange |
canonical(org.datavec.dataframe.util.collections.IntegerDomain domain)
Returns the canonical form of this range in the given domain.
|
static IntRange |
closed(int lower,
int upper)
Returns a range that contains all values greater than or equal to
lower and less than or equal to upper . |
static IntRange |
closedOpen(int lower,
int upper)
Returns a range that contains all values greater than or equal to
lower and strictly less than upper . |
boolean |
contains(int value)
Returns
true if value is within the bounds of this range. |
boolean |
containsAll(it.unimi.dsi.fastutil.ints.IntCollection values)
|
static IntRange |
downTo(int endpoint,
com.google.common.collect.BoundType boundType)
Returns a range from the given endpoint, which may be either inclusive
(closed) or exclusive (open), with no upper bound.
|
static IntRange |
encloseAll(it.unimi.dsi.fastutil.ints.IntCollection values)
Returns the minimal range that
contains all of the given values.
|
boolean |
encloses(IntRange other)
Returns
true if the bounds of other do not extend outside the bounds of this
range. |
boolean |
equals(java.lang.Object object)
Returns
true if object is a range having the same endpoints and bound types as
this range. |
static IntRange |
greaterThan(int endpoint)
Returns a range that contains all values strictly greater than
endpoint . |
int |
hashCode()
Returns a hash code for this range.
|
boolean |
hasLowerBound()
Returns
true if this range has a lower endpoint. |
boolean |
hasUpperBound()
Returns
true if this range has an upper endpoint. |
IntRange |
intersection(IntRange connectedRange)
Returns the maximal range enclosed by both this range and
connectedRange , if such a range exists. |
boolean |
isConnected(IntRange other)
Returns
true if there exists a (possibly empty) range which is enclosed by both this range and other . |
boolean |
isEmpty()
Returns
true if this range is of the form [v..v) or (v..v] . |
static IntRange |
lessThan(int endpoint)
Returns a range that contains all values strictly less than
endpoint . |
org.datavec.dataframe.util.collections.IntCut |
lowerBound() |
com.google.common.collect.BoundType |
lowerBoundType()
Returns the type of this range's lower bound:
BoundType.CLOSED if the range includes
its lower endpoint, BoundType.OPEN if it does not. |
int |
lowerEndpoint()
Returns the lower endpoint of this range.
|
static IntRange |
open(int lower,
int upper)
Returns a range that contains all values strictly greater than
lower and strictly less than upper . |
static IntRange |
openClosed(int lower,
int upper)
Returns a range that contains all values strictly greater than
lower and less than or equal to upper . |
static IntRange |
range(int lower,
com.google.common.collect.BoundType lowerType,
int upper,
com.google.common.collect.BoundType upperType)
Returns a range that contains any value from
lower to upper , where each endpoint may be either inclusive (closed) or exclusive
(open). |
static IntRange |
singleton(int value)
Returns a range that contains only
the given value.
|
IntRange |
span(IntRange other)
Returns the minimal range that encloses both this range and
other . |
java.lang.String |
toString()
Returns a string representation of this range, such as
"[3..5)" (other examples are
listed in the class documentation). |
org.datavec.dataframe.util.collections.IntCut |
upperBound() |
com.google.common.collect.BoundType |
upperBoundType()
Returns the type of this range's upper bound:
BoundType.CLOSED if the range includes
its upper endpoint, BoundType.OPEN if it does not. |
int |
upperEndpoint()
Returns the upper endpoint of this range.
|
static IntRange |
upTo(int endpoint,
com.google.common.collect.BoundType boundType)
Returns a range with no lower bound up to the given endpoint, which may be
either inclusive (closed) or exclusive (open).
|
public static IntRange open(int lower, int upper)
lower
and strictly less than upper
.java.lang.IllegalArgumentException
- if lower
is greater than or
equal to upper
public static IntRange closed(int lower, int upper)
lower
and less than or equal to upper
.java.lang.IllegalArgumentException
- if lower
is greater than upper
public static IntRange closedOpen(int lower, int upper)
lower
and strictly less than upper
.java.lang.IllegalArgumentException
- if lower
is greater than upper
public static IntRange openClosed(int lower, int upper)
lower
and less than or equal to upper
.java.lang.IllegalArgumentException
- if lower
is greater than upper
public static IntRange range(int lower, com.google.common.collect.BoundType lowerType, int upper, com.google.common.collect.BoundType upperType)
lower
to upper
, where each endpoint may be either inclusive (closed) or exclusive
(open).java.lang.IllegalArgumentException
- if lower
is greater than upper
public static IntRange lessThan(int endpoint)
endpoint
.public static IntRange atMost(int endpoint)
endpoint
.public static IntRange upTo(int endpoint, com.google.common.collect.BoundType boundType)
public static IntRange greaterThan(int endpoint)
endpoint
.public static IntRange atLeast(int endpoint)
endpoint
.public static IntRange downTo(int endpoint, com.google.common.collect.BoundType boundType)
public static IntRange all()
int
.public static IntRange singleton(int value)
public static IntRange encloseAll(it.unimi.dsi.fastutil.ints.IntCollection values)
java.lang.ClassCastException
- if the parameters are not mutually
comparablejava.util.NoSuchElementException
- if values
is emptyjava.lang.NullPointerException
- if any of values
is nullpublic org.datavec.dataframe.util.collections.IntCut upperBound()
public org.datavec.dataframe.util.collections.IntCut lowerBound()
public boolean hasLowerBound()
true
if this range has a lower endpoint.public int lowerEndpoint()
java.lang.IllegalStateException
- if this range is unbounded below (that is, hasLowerBound()
returns false
)public com.google.common.collect.BoundType lowerBoundType()
BoundType.CLOSED
if the range includes
its lower endpoint, BoundType.OPEN
if it does not.java.lang.IllegalStateException
- if this range is unbounded below (that is, hasLowerBound()
returns false
)public boolean hasUpperBound()
true
if this range has an upper endpoint.public int upperEndpoint()
java.lang.IllegalStateException
- if this range is unbounded above (that is, hasUpperBound()
returns false
)public com.google.common.collect.BoundType upperBoundType()
BoundType.CLOSED
if the range includes
its upper endpoint, BoundType.OPEN
if it does not.java.lang.IllegalStateException
- if this range is unbounded above (that is, hasUpperBound()
returns false
)public boolean isEmpty()
true
if this range is of the form [v..v)
or (v..v]
. (This does
not encompass ranges of the form (v..v)
, because such ranges are invalid and
can't be constructed at all.)
Note that certain discrete ranges such as the integer range (3..4)
are not
considered empty, even though they contain no actual values. In these cases, it may be
helpful to preprocess ranges with canonical(IntegerDomain)
.
public boolean contains(int value)
true
if value
is within the bounds of this range. For example, on the
range [0..2)
, contains(1)
returns true
, while contains(2)
returns false
.public boolean containsAll(it.unimi.dsi.fastutil.ints.IntCollection values)
public boolean encloses(IntRange other)
true
if the bounds of other
do not extend outside the bounds of this
range. Examples:
[3..6]
encloses [4..5]
(3..6)
encloses (3..6)
[3..6]
encloses [4..4)
(even though the latter is empty)
(3..6]
does not enclose [3..6]
[4..5]
does not enclose (3..6)
(even though it contains every value
contained by the latter range)
[3..6]
does not enclose (1..1]
(even though it contains every value
contained by the latter range)
Note that if a.encloses(b)
, then b.contains(v)
implies
a.contains(v)
, but as the last two examples illustrate, the converse is not always
true.
Being reflexive, antisymmetric and transitive, the encloses
relation defines a
partial order over ranges. There exists a unique maximal range
according to this relation, and also numerous minimal ranges. Enclosure
also implies connectedness.
public boolean isConnected(IntRange other)
true
if there exists a (possibly empty) range which is enclosed by both this range and other
.
For example,
[2, 4)
and [5, 7)
are not connected
[2, 4)
and [3, 5)
are connected, because both enclose [3, 4)
[2, 4)
and [4, 6)
are connected, because both enclose the empty range
[4, 4)
Note that this range and other
have a well-defined union and
intersection (as a single, possibly-empty range) if and only if this
method returns true
.
The connectedness relation is both reflexive and symmetric, but does not form an equivalence relation as it is not transitive.
Note that certain discrete ranges are not considered connected, even though there are no
elements "between them." For example, [3, 5]
is not considered connected to [6, 10]
. In these cases, it may be desirable for both input ranges to be preprocessed with
canonical(IntegerDomain)
before testing for connectedness.
public IntRange intersection(IntRange connectedRange)
connectedRange
, if such a range exists.
For example, the intersection of [1..5]
and (3..7)
is (3..5]
. The
resulting range may be empty; for example, [1..5)
intersected with [5..7)
yields the empty range [5..5)
.
The intersection exists if and only if the two ranges are connected.
The intersection operation is commutative, associative and idempotent, and its identity
element is all()
).
java.lang.IllegalArgumentException
- if isConnected(connectedRange)
is false
public IntRange span(IntRange other)
other
. For example, the span of [1..3]
and (5..7)
is [1..7)
.
If the input ranges are connected, the returned range can also be called their union. If they are not, note that the span might contain values that are not contained in either input range.
Like intersection
, this operation is commutative, associative
and idempotent. Unlike it, it is always well-defined for any two input ranges.
public IntRange canonical(org.datavec.dataframe.util.collections.IntegerDomain domain)
a.canonical().contains(v) == a.contains(v)
for all v
(in other
words, ContiguousSet.createFromCsv(a.canonical(domain), domain).equals(
ContiguousSet.createFromCsv(a, domain))
a.isEmpty()
,
ContiguousSet.createFromCsv(a, domain).equals(ContiguousSet.createFromCsv(b, domain))
implies
a.canonical(domain).equals(b.canonical(domain))
a.canonical(domain).canonical(domain).equals(a.canonical(domain))
Furthermore, this method guarantees that the range returned will be one of the following canonical forms:
int
is unbounded below)
int
is unbounded below)
public boolean equals(@Nullable java.lang.Object object)
true
if object
is a range having the same endpoints and bound types as
this range. Note that discrete ranges such as (1..4)
and [2..3]
are not
equal to one another, despite the fact that they each contain precisely the same set of values.
Similarly, empty ranges are not equal unless they have exactly the same representation, so
[3..3)
, (3..3]
, (4..4]
are all unequal.equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
"[3..5)"
(other examples are
listed in the class documentation).toString
in class java.lang.Object