java.lang.Object | |
↳ | android.util.Range<T extends java.lang.Comparable<? super T>> |
Immutable class for describing the range of two numeric values.
A range (or "interval") defines the inclusive boundaries around a contiguous span of
values of some Comparable
type; for example,
"integers from 1 to 100 inclusive."
All ranges are bounded, and the left side of the range is always >=
the right side of the range.
Although the implementation itself is immutable, there is no restriction that objects stored must also be immutable. If mutable objects are stored here, then the range effectively becomes mutable.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new immutable range.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clamps
value to this range.
| |||||||||||
Checks if another
range is within the bounds of this range.
| |||||||||||
Checks if the
value is within the bounds of this range.
| |||||||||||
Create a new immutable range, with the argument types inferred.
| |||||||||||
Compare two ranges for equality.
| |||||||||||
Returns the smallest range that includes this range and
the
value .
| |||||||||||
Returns the smallest range that includes this range and
another
range .
| |||||||||||
Returns the smallest range that includes this range and
the inclusive range specified by
[lower, upper] .
| |||||||||||
Get the lower endpoint.
| |||||||||||
Get the upper endpoint.
| |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Returns the intersection of this range and another
range .
| |||||||||||
Returns the intersection of this range and the inclusive range
specified by
[lower, upper] .
| |||||||||||
Return the range as a string representation
"[lower, upper]" .
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create a new immutable range.
The endpoints are [lower, upper]
; that
is the range is bounded. lower
must be lesser or equal
to upper
.
lower | The lower endpoint (inclusive) |
---|---|
upper | The upper endpoint (inclusive) |
NullPointerException | if lower or upper is null
|
---|
Clamps value
to this range.
If the value is within this range, it is returned. Otherwise, if it
is <
than the lower endpoint, the lower endpoint is returned,
else the upper endpoint is returned. Comparisons are performed using the
Comparable
interface.
value | a non-null T reference |
---|
value
clamped to this range.
Checks if another range
is within the bounds of this range.
A range is considered to be within this range if both of its endpoints are within this range.
range | a non-null T reference |
---|
true
if the range is within this inclusive range, false
otherwiseNullPointerException | if range was null
|
---|
Checks if the value
is within the bounds of this range.
A value is considered to be within this range if it's >=
the lower endpoint and <=
the upper endpoint (using the Comparable
interface.)
value | a non-null T reference |
---|
true
if the value is within this inclusive range, false
otherwiseNullPointerException | if value was null
|
---|
Create a new immutable range, with the argument types inferred.
The endpoints are [lower, upper]
; that
is the range is bounded. lower
must be lesser or equal
to upper
.
lower | The lower endpoint (inclusive) |
---|---|
upper | The upper endpoint (inclusive) |
NullPointerException | if lower or upper is null
|
---|
Compare two ranges for equality.
A range is considered equal if and only if both the lower and upper endpoints are also equal.
obj | the object to compare this instance with. |
---|
true
if the ranges are equal, false
otherwise
Returns the smallest range that includes this range and
the value
.
See extend(Range)
for more details, as this method is
equivalent to extend(Range.create(value, value))
.
value | a non-null T reference |
---|
NullPointerException | if value was null
|
---|
Returns the smallest range that includes this range and
another range
.
E.g. if a <
b <
c <
d, the
extension of [a, c] and [b, d] ranges is [a, d].
As the endpoints are object references, there is no guarantee
which specific endpoint reference is used from the input ranges:
E.g. if a ==
a' <
b <
c, the
extension of [a, b] and [a', c] ranges could be either
[a, c] or ['a, c], where ['a, c] could be either the exact
input range, or a newly created range with the same endpoints.
range | a non-null Range reference |
---|
NullPointerException | if range was null
|
---|
Returns the smallest range that includes this range and
the inclusive range specified by [lower, upper]
.
See extend(Range)
for more details.
lower | a non-null T reference |
---|---|
upper | a non-null T reference |
NullPointerException | if lower or upper was null
|
---|
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
Returns the intersection of this range and another range
.
E.g. if a <
b <
c <
d, the
intersection of [a, c] and [b, d] ranges is [b, c].
As the endpoints are object references, there is no guarantee
which specific endpoint reference is used from the input ranges:
E.g. if a ==
a' <
b <
c, the
intersection of [a, b] and [a', c] ranges could be either
[a, b] or ['a, b], where [a, b] could be either the exact
input range, or a newly created range with the same endpoints.
range | a non-null Range reference |
---|
NullPointerException | if range was null |
---|---|
IllegalArgumentException | if the ranges are disjoint. |
Returns the intersection of this range and the inclusive range
specified by [lower, upper]
.
See intersect(Range)
for more details.
lower | a non-null T reference |
---|---|
upper | a non-null T reference |
NullPointerException | if lower or upper was null |
---|---|
IllegalArgumentException | if the ranges are disjoint. |
Return the range as a string representation "[lower, upper]"
.