|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectRange
Range<T>
NumberRange<T>
T - The type of range elements as a subclass of Number.@Immutable public class NumberRange<T extends Number & Comparable<? super T>>
A range of numbers. Union and intersection are computed as usual, except that widening conversions will be applied as needed.
NumberRange has no units. For a range of physical measurements with units of
measure, see MeasurementRange.
RangeFormat,
Serialized Form
| utility/geotk-utility (download) | View source code for this class |
| Constructor Summary | |
|---|---|
NumberRange(Class<T> type,
T minimum,
boolean isMinIncluded,
T maximum,
boolean isMaxIncluded)
Constructs a range of Number objects. |
|
NumberRange(Class<T> type,
T minimum,
T maximum)
Constructs an inclusive range of Number objects. |
|
NumberRange(Class<T> type,
ValueRange range)
Creates a new range from the given annotation. |
|
NumberRange(Range<T> range)
Constructs a range with the same type and the same values than the specified range. |
|
| Method Summary | ||
|---|---|---|
|
castTo(Class<N> type)
Casts this range to the specified type. |
|
boolean |
contains(Comparable value)
Returns true if the specified value is within this range. |
|
boolean |
contains(Number value)
Returns true if the specified value is within this range. |
|
boolean |
contains(Range<?> range)
Returns true if the supplied range is fully contained within this range. |
|
static NumberRange<Byte> |
create(byte minimum,
boolean isMinIncluded,
byte maximum,
boolean isMaxIncluded)
Constructs a range of byte values. |
|
static NumberRange<Byte> |
create(byte minimum,
byte maximum)
Constructs an inclusive range of byte values. |
|
static NumberRange<Double> |
create(double minimum,
boolean isMinIncluded,
double maximum,
boolean isMaxIncluded)
Constructs a range of double values. |
|
static NumberRange<Double> |
create(double minimum,
double maximum)
Constructs an inclusive range of double values. |
|
static NumberRange<Float> |
create(float minimum,
boolean isMinIncluded,
float maximum,
boolean isMaxIncluded)
Constructs a range of float values. |
|
static NumberRange<Float> |
create(float minimum,
float maximum)
Constructs an inclusive range of float values. |
|
static NumberRange<Integer> |
create(int minimum,
boolean isMinIncluded,
int maximum,
boolean isMaxIncluded)
Constructs a range of int values. |
|
static NumberRange<Integer> |
create(int minimum,
int maximum)
Constructs an inclusive range of int values. |
|
static NumberRange<Long> |
create(long minimum,
boolean isMinIncluded,
long maximum,
boolean isMaxIncluded)
Constructs a range of long values. |
|
static NumberRange<Long> |
create(long minimum,
long maximum)
Constructs an inclusive range of long values. |
|
static NumberRange<Short> |
create(short minimum,
boolean isMinIncluded,
short maximum,
boolean isMaxIncluded)
Constructs a range of short values. |
|
static NumberRange<Short> |
create(short minimum,
short maximum)
Constructs an inclusive range of short values. |
|
static NumberRange<?> |
createBestFit(Number minimum,
boolean isMinIncluded,
Number maximum,
boolean isMaxIncluded)
Constructs a range using the smallest type of Number that can hold the
given values. |
|
double |
getMaximum()
Returns the maximum value as a double. |
|
double |
getMaximum(boolean inclusive)
Returns the maximum value with the specified inclusive or exclusive state. |
|
double |
getMinimum()
Returns the minimum value as a double. |
|
double |
getMinimum(boolean inclusive)
Returns the minimum value with the specified inclusive or exclusive state. |
|
NumberRange<?> |
intersect(Range<?> range)
Returns the intersection between this range and the provided range. |
|
boolean |
intersects(Range<?> range)
Returns true if this range intersects the given range. |
|
NumberRange<?>[] |
subtract(Range<?> range)
Returns the range of values that are in this range but not in the given range. |
|
NumberRange<?> |
union(Range<?> range)
Returns the union of this range with the given range. |
|
static
|
wrap(Range<N> range)
Wraps the specified Range in a NumberRange object. |
|
| Methods inherited from class Range |
|---|
equals, getElementType, getMaxValue, getMinValue, hashCode, isMaxIncluded, isMinIncluded, toString |
| Methods inherited from class Range |
|---|
contains, formatTo, intersect, intersects, isEmpty, subtract, union |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public NumberRange(Class<T> type,
T minimum,
T maximum)
Number objects.
type - The element class, usually one of Byte, Short,
Integer, Long, Float or Double.minimum - The minimum value, inclusive.maximum - The maximum value, inclusive.
public NumberRange(Class<T> type,
T minimum,
boolean isMinIncluded,
T maximum,
boolean isMaxIncluded)
Number objects.
type - The element class, usually one of Byte, Short,
Integer, Long, Float or Double.minimum - The minimum value.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value.isMaxIncluded - Defines whether the maximum value is included in the range.
public NumberRange(Class<T> type,
ValueRange range)
type - The element class, usually one of Byte, Short,
Integer, Long, Float or Double.range - The range of value.public NumberRange(Range<T> range)
range - The range to copy. The elements must be Number instances.| Method Detail |
|---|
public static NumberRange<Byte> create(byte minimum,
byte maximum)
byte values.
minimum - The minimum value, inclusive.maximum - The maximum value, inclusive.
public static NumberRange<Byte> create(byte minimum,
boolean isMinIncluded,
byte maximum,
boolean isMaxIncluded)
byte values.
minimum - The minimum value.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value.isMaxIncluded - Defines whether the maximum value is included in the range.
public static NumberRange<Short> create(short minimum,
short maximum)
short values.
minimum - The minimum value, inclusive.maximum - The maximum value, inclusive.
public static NumberRange<Short> create(short minimum,
boolean isMinIncluded,
short maximum,
boolean isMaxIncluded)
short values.
minimum - The minimum value.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value.isMaxIncluded - Defines whether the maximum value is included in the range.
public static NumberRange<Integer> create(int minimum,
int maximum)
int values.
minimum - The minimum value, inclusive.maximum - The maximum value, inclusive.
public static NumberRange<Integer> create(int minimum,
boolean isMinIncluded,
int maximum,
boolean isMaxIncluded)
int values.
minimum - The minimum value.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value.isMaxIncluded - Defines whether the maximum value is included in the range.
public static NumberRange<Long> create(long minimum,
long maximum)
long values.
minimum - The minimum value, inclusive.maximum - The maximum value, inclusive.
public static NumberRange<Long> create(long minimum,
boolean isMinIncluded,
long maximum,
boolean isMaxIncluded)
long values.
minimum - The minimum value.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value.isMaxIncluded - Defines whether the maximum value is included in the range.
public static NumberRange<Float> create(float minimum,
float maximum)
float values.
minimum - The minimum value, inclusive.maximum - The maximum value, inclusive.
public static NumberRange<Float> create(float minimum,
boolean isMinIncluded,
float maximum,
boolean isMaxIncluded)
float values.
minimum - The minimum value.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value.isMaxIncluded - Defines whether the maximum value is included in the range.
public static NumberRange<Double> create(double minimum,
double maximum)
double values.
minimum - The minimum value, inclusive.maximum - The maximum value, inclusive.
public static NumberRange<Double> create(double minimum,
boolean isMinIncluded,
double maximum,
boolean isMaxIncluded)
double values.
minimum - The minimum value.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value.isMaxIncluded - Defines whether the maximum value is included in the range.
public static NumberRange<?> createBestFit(Number minimum,
boolean isMinIncluded,
Number maximum,
boolean isMaxIncluded)
Number that can hold the
given values. The given numbers don't need to be of the same type since they will
be casted
as needed. More specifically:
Byte objects and a NumberRange is created from them.Short objects and a NumberRange is created from them.Integer type is tested in the same way, then the
Long type, and finally the Float type.Double type is used.
minimum - The minimum value, or null for negative infinity.isMinIncluded - Defines whether the minimum value is included in the range.maximum - The maximum value, or null for positive infinity.isMaxIncluded - Defines whether the maximum value is included in the range.
null if both minimum and maximum
are null.public static <N extends Number & Comparable<? super N>> NumberRange<N> wrap(Range<N> range)
Range in a NumberRange object. If the specified
range is already an instance of NumberRange, then it is returned unchanged.
N - The type of elements in the given range.range - The range to wrap.
range as a NumberRange object.
public <N extends Number & Comparable<? super N>> NumberRange<N> castTo(Class<N> type)
throws IllegalArgumentException
N - The class to cast to.type - The class to cast to. Must be one of Byte, Short,
Integer, Long, Float or Double.
this if this range already uses the specified type.
IllegalArgumentException - if the values are not convertible to the specified class.
public boolean contains(Number value)
throws IllegalArgumentException
true if the specified value is within this range.
value - The value to check for inclusion.
true if the given value is within this range.
IllegalArgumentException - if the given value is not comparable.
public boolean contains(Comparable value)
throws IllegalArgumentException
true if the specified value is within this range.
The given value must be a subclass of Number.
contains in class Range<T extends Number & Comparable<? super T>>value - The value to check for inclusion in this range.
true if the given value is included in this range.
IllegalArgumentException - if the given value is not a subclass of Number.
public boolean contains(Range<?> range)
throws IllegalArgumentException
true if the supplied range is fully contained within this range.
contains in class Range<T extends Number & Comparable<? super T>>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 can not be converted to a valid type
through widening conversion, or if the units of measurement are not convertible.
public boolean intersects(Range<?> range)
throws IllegalArgumentException
true if this range intersects the given range.
intersects in class Range<T extends Number & Comparable<? super T>>range - The range to check for intersection with this range.
true if the given range intersects this range.
IllegalArgumentException - is the given range can not be converted to a valid type
through widening conversion, or if the units of measurement are not convertible.Range.intersects(javax.media.jai.util.Range)
public NumberRange<?> union(Range<?> range)
throws IllegalArgumentException
union in class Range<T extends Number & Comparable<? super T>>range - The range to add to this range.
IllegalArgumentException - is the given range can not be converted to a valid type
through widening conversion, or if the units of measurement are not convertible.Range.union(javax.media.jai.util.Range)
public NumberRange<?> intersect(Range<?> range)
throws IllegalArgumentException
intersect in class Range<T extends Number & Comparable<? super T>>range - The range to intersect.
IllegalArgumentException - is the given range can not be converted to a valid type
through widening conversion, or if the units of measurement are not convertible.Range.intersect(javax.media.jai.util.Range)
public NumberRange<?>[] subtract(Range<?> range)
throws IllegalArgumentException
subtract in class Range<T extends Number & Comparable<? super T>>range - The range to subtract.
IllegalArgumentException - is the given range can not be converted to a valid type
through widening conversion, or if the units of measurement are not convertible.Range.subtract(javax.media.jai.util.Range)public double getMinimum()
double.
If this range is unbounded, then Double.NEGATIVE_INFINITY is returned.
public double getMinimum(boolean inclusive)
Double.NEGATIVE_INFINITY is
returned.
inclusive - true for the minimum value inclusive, or false
for the minimum value exclusive.
public double getMaximum()
double.
If this range is unbounded, then Double.POSITIVE_INFINITY is returned.
public double getMaximum(boolean inclusive)
Double.POSITIVE_INFINITY is
returned.
inclusive - true for the maximum value inclusive, or false
for the maximum value exclusive.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||