@Immutable public class Range<E extends Comparable<? super E>> extends Object implements CheckedContainer<E>, Formattable, Serializable
The minimal and maximal values (the endpoints) may be inclusive or exclusive.
Numeric ranges where both endpoints are inclusive are called closed intervals
and are represented by square brackets, for example "[0 … 255]
".
Numeric ranges where both endpoints are exclusive are called open intervals
and are represented by parenthesis, for example "(0 … 256)
".
Range
, the <E>
type defining the range must implement the
Comparable
interface. All argument values given to the methods of this class shall be
or contain instances of that <E>
type. The type is enforced by parameterized type,
but some subclasses may put additional constraints. For example MeasurementRange
will
additionally checks the units of measurement. Consequently every methods defined in this class
may throw an IllegalArgumentException
if a given argument does not meet some constraint
beyond the type.
The characteristics of the spatial domain are defined by the ISO 19123 standard whereas the
characteristics of the attribute range are not part of that standard. In Apache SIS, those
characteristics are described by the org.apache.sis.coverage.SampleDimension
class,
which may contain one or many Range
instances. Consequently this Range
class
is closely related, but not identical, to the ISO 19123 definition or range.
Ranges are not necessarily numeric. Numeric and non-numeric ranges can be associated to discrete coverages, while typically only numeric ranges can be associated to continuous coverages.
RangeFormat
,
RangeSet
,
Serialized FormDefined in the sis-utility module
Constructor and Description |
---|
Range(Class<E> elementType,
E minValue,
boolean isMinIncluded,
E maxValue,
boolean isMaxIncluded)
Creates a new range bounded by the given endpoint values.
|
Range(Range<E> range)
Constructs a range with the same type and the same values than the specified range.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(E value)
Returns
true if this range contains the given value. |
boolean |
contains(Range<? extends E> range)
Returns
true if the supplied range is fully contained within this range. |
boolean |
equals(Object object)
Compares this range with the given object for equality.
|
void |
formatTo(Formatter formatter,
int flags,
int width,
int precision)
Formats this range using the provider formatter.
|
Class<E> |
getElementType()
Returns the base type of elements in this range.
|
E |
getMaxValue()
Returns the maximal value, or
null if this range has no upper limit. |
E |
getMinValue()
Returns the minimal value, or
null if this range has no lower limit. |
int |
hashCode()
Returns a hash code value for this range.
|
Range<E> |
intersect(Range<E> range)
Returns the intersection between this range and the given range.
|
boolean |
intersects(Range<? extends E> range)
Returns
true if this range intersects the given range. |
boolean |
isEmpty()
Returns
true if this range is empty. |
boolean |
isMaxIncluded()
|
boolean |
isMinIncluded()
|
Range<E>[] |
subtract(Range<E> range)
Returns the range of values that are in this range but not in the given range.
|
String |
toString()
Returns a unlocalized string representation of this range.
|
Range<E> |
union(Range<E> range)
Returns the union of this range with the given range.
|
public Range(Range<E> range)
range
- The range to copy.public Range(Class<E> elementType, E minValue, boolean isMinIncluded, E maxValue, boolean isMaxIncluded)
elementType
- The base type of the range elements.minValue
- The minimal value, or null
if none.isMinIncluded
- true
if the minimal value is inclusive, or false
if exclusive.maxValue
- The maximal value, or null
if none.isMaxIncluded
- true
if the maximal value is inclusive, or false
if exclusive.public Class<E> getElementType()
getElementType
in interface CheckedContainer<E extends Comparable<? super E>>
public E getMinValue()
null
if this range has no lower limit.
If non-null, the returned value is either inclusive or exclusive depending on
the boolean returned by isMinIncluded()
.null
if this range is unbounded on the lower side.public boolean isMinIncluded()
true
if the minimal value is inclusive,
or false
if exclusive. Note that null
values are always considered
exclusive.true
if the minimal value is inclusive, or false
if exclusive.public E getMaxValue()
null
if this range has no upper limit.
If non-null, the returned value is either inclusive or exclusive depending on
the boolean returned by isMaxIncluded()
.null
if this range is unbounded on the upper side.public boolean isMaxIncluded()
true
if the maximal value is inclusive,
or false
if exclusive. Note that null
values are always considered
exclusive.true
if the maximal value is inclusive, or false
if exclusive.public final boolean isEmpty()
true
if this range is empty. A range is empty if the
minimum value is smaller than the
maximum value, or if they are equal while
at least one of them is exclusive.
Note: This method is final because often used by the internal implementation. Making the method final ensures that the other methods behave consistently.
true
if this range is empty.public boolean contains(E value)
true
if this range contains the given value. A range never contains the
null
value. This is consistent with the class javadoc
stating that null minimum or maximum
values are exclusive.value
- The value to check for inclusion in this range.true
if the given value is included in this range.public boolean contains(Range<? extends E> range)
true
if the supplied range is fully contained within this range.range
- The range to check for inclusion in this range.true
if the given range is included in this range.IllegalArgumentException
- is the given range is incompatible,
for example because of incommensurable units of measurement.public boolean intersects(Range<? extends E> range)
true
if this range intersects the given range.range
- The range to check for intersection with this range.true
if the given range intersects this range.IllegalArgumentException
- is the given range is incompatible,
for example because of incommensurable units of measurement.public Range<E> intersect(Range<E> range)
range
- The range to intersect.IllegalArgumentException
- is the given range is incompatible,
for example because of incommensurable units of measurement.public Range<E> union(Range<E> range)
range
- The range to add to this range.IllegalArgumentException
- is the given range is incompatible,
for example because of incommensurable units of measurement.public Range<E>[] subtract(Range<E> range)
range
- The range to subtract.IllegalArgumentException
- is the given range is incompatible,
for example because of incommensurable units of measurement.public boolean equals(Object object)
public int hashCode()
public String toString()
…
" character
instead than coma. More specifically, the string representation is defined as below:
{}
".{value}
".[min … max]
" for inclusive endpoints or "(min … max)
" for exclusive
endpoints, or a mix of both styles. The "∞
" symbol is used in place of
min
or max
for unbounded ranges.MeasurementRange
, then the unit of measurement
is appended to the above string representation except for empty ranges.toString
in class Object
RangeFormat
,
Wikipedia: ISO 31-11public void formatTo(Formatter formatter, int flags, int width, int precision)
Range
object is formatted using the "%s"
conversion specifier of
Formatter
. Users don't need to invoke this method explicitely.
If the alternate flags is present (as in "%#s"
), then the range will
be formatted using the alternate form
for exclusive bounds.
formatTo
in interface Formattable
formatter
- The formatter in which to format this angle.flags
- FormattableFlags.LEFT_JUSTIFY
for left alignment, or 0 for right alignment.width
- Minimal number of characters to write, padding with ' '
if necessary.precision
- Maximal number of characters to write, or -1 if no limit.Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.