Package org.geotools.util
Class NumberRange<T extends Number & Comparable<? super T>>
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MeasurementRange
public class NumberRange<T extends Number & Comparable<? super T>> extends Range<T>
A range of numbers. Union and intersection are computed as usual, except that widening conversions will be applied as needed.- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description NumberRange(Class<T> type, T minimum, boolean isMinIncluded, T maximum, boolean isMaxIncluded)
Constructs a range ofNumber
objects.NumberRange(Class<T> type, T minimum, T maximum)
Constructs an inclusive range ofNumber
objects.NumberRange(Range<T> range)
Constructs a range with the same type and the same values than the specified range.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <N extends Number & Comparable<? super N>>
NumberRange<N>castTo(Class<N> type)
Casts this range to the specified type.boolean
contains(Comparable<?> value)
Returnstrue
if the specified value is within this range.boolean
contains(Number value)
Returnstrue
if the specified value is within this range.boolean
contains(Range<?> range)
Returnstrue
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 ofbyte
values.static NumberRange<Byte>
create(byte minimum, byte maximum)
Constructs an inclusive range ofbyte
values.static NumberRange<Double>
create(double minimum, boolean isMinIncluded, double maximum, boolean isMaxIncluded)
Constructs a range ofdouble
values.static NumberRange<Double>
create(double minimum, double maximum)
Constructs an inclusive range ofdouble
values.static NumberRange<Float>
create(float minimum, boolean isMinIncluded, float maximum, boolean isMaxIncluded)
Constructs a range offloat
values.static NumberRange<Float>
create(float minimum, float maximum)
Constructs an inclusive range offloat
values.static NumberRange<Integer>
create(int minimum, boolean isMinIncluded, int maximum, boolean isMaxIncluded)
Constructs a range ofint
values.static NumberRange<Integer>
create(int minimum, int maximum)
Constructs an inclusive range ofint
values.static NumberRange<Long>
create(long minimum, boolean isMinIncluded, long maximum, boolean isMaxIncluded)
Constructs a range oflong
values.static NumberRange<Long>
create(long minimum, long maximum)
Constructs an inclusive range oflong
values.static NumberRange<Short>
create(short minimum, boolean isMinIncluded, short maximum, boolean isMaxIncluded)
Constructs a range ofshort
values.static NumberRange<Short>
create(short minimum, short maximum)
Constructs an inclusive range ofshort
values.double
getMaximum()
Returns the maximum value as adouble
.double
getMaximum(boolean inclusive)
Returns the maximum value with the specified inclusive or exclusive state.double
getMinimum()
Returns the minimum value as adouble
.double
getMinimum(boolean inclusive)
Returns the minimum value with the specified inclusive or exclusive state.NumberRange<?>
intersect(Range<?> range)
Returns the intersection of this range with the given range.boolean
intersects(Range<?> range)
Returnstrue
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 <N extends Number & Comparable<? super N>>
NumberRange<N>wrap(Range<N> range)
Wraps the specifiedRange
in aNumberRange
object.-
Methods inherited from class Range
equals, getElementClass, getMaxValue, getMinValue, hashCode, isEmpty, isMaxIncluded, isMinIncluded, toString
-
-
-
-
Constructor Detail
-
NumberRange
public NumberRange(Class<T> type, T minimum, T maximum)
Constructs an inclusive range ofNumber
objects.
-
NumberRange
public NumberRange(Class<T> type, T minimum, boolean isMinIncluded, T maximum, boolean isMaxIncluded)
Constructs a range ofNumber
objects.- Parameters:
type
- The element class, usually one ofByte
,Short
,Integer
,Long
,Float
orDouble
.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.
-
-
Method Detail
-
create
public static NumberRange<Byte> create(byte minimum, byte maximum)
Constructs an inclusive range ofbyte
values.- Parameters:
minimum
- The minimum value, inclusive.maximum
- The maximum value, inclusive.- Since:
- 2.5
-
create
public static NumberRange<Byte> create(byte minimum, boolean isMinIncluded, byte maximum, boolean isMaxIncluded)
Constructs a range ofbyte
values.- Parameters:
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.- Since:
- 2.5
-
create
public static NumberRange<Short> create(short minimum, short maximum)
Constructs an inclusive range ofshort
values.- Parameters:
minimum
- The minimum value, inclusive.maximum
- The maximum value, inclusive.- Since:
- 2.5
-
create
public static NumberRange<Short> create(short minimum, boolean isMinIncluded, short maximum, boolean isMaxIncluded)
Constructs a range ofshort
values.- Parameters:
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.- Since:
- 2.5
-
create
public static NumberRange<Integer> create(int minimum, int maximum)
Constructs an inclusive range ofint
values.- Parameters:
minimum
- The minimum value, inclusive.maximum
- The maximum value, inclusive.- Since:
- 2.5
-
create
public static NumberRange<Integer> create(int minimum, boolean isMinIncluded, int maximum, boolean isMaxIncluded)
Constructs a range ofint
values.- Parameters:
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.- Since:
- 2.5
-
create
public static NumberRange<Long> create(long minimum, long maximum)
Constructs an inclusive range oflong
values.- Parameters:
minimum
- The minimum value, inclusive.maximum
- The maximum value, inclusive.- Since:
- 2.5
-
create
public static NumberRange<Long> create(long minimum, boolean isMinIncluded, long maximum, boolean isMaxIncluded)
Constructs a range oflong
values.- Parameters:
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.- Since:
- 2.5
-
create
public static NumberRange<Float> create(float minimum, float maximum)
Constructs an inclusive range offloat
values.- Parameters:
minimum
- The minimum value, inclusive.maximum
- The maximum value, inclusive.- Since:
- 2.5
-
create
public static NumberRange<Float> create(float minimum, boolean isMinIncluded, float maximum, boolean isMaxIncluded)
Constructs a range offloat
values.- Parameters:
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.- Since:
- 2.5
-
create
public static NumberRange<Double> create(double minimum, double maximum)
Constructs an inclusive range ofdouble
values.- Parameters:
minimum
- The minimum value, inclusive.maximum
- The maximum value, inclusive.- Since:
- 2.5
-
create
public static NumberRange<Double> create(double minimum, boolean isMinIncluded, double maximum, boolean isMaxIncluded)
Constructs a range ofdouble
values.- Parameters:
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.- Since:
- 2.5
-
wrap
public static <N extends Number & Comparable<? super N>> NumberRange<N> wrap(Range<N> range)
Wraps the specifiedRange
in aNumberRange
object. If the specified range is already an instance ofNumberRange
, then it is returned unchanged.- Type Parameters:
N
- The type of elements in the given range.- Parameters:
range
- The range to wrap.- Returns:
- The same range than
range
as aNumberRange
object.
-
castTo
public <N extends Number & Comparable<? super N>> NumberRange<N> castTo(Class<N> type) throws IllegalArgumentException
Casts this range to the specified type.- Type Parameters:
N
- The class to cast to.- Parameters:
type
- The class to cast to. Must be one ofByte
,Short
,Integer
,Long
,Float
orDouble
.- Returns:
- The casted range, or
this
if this range already uses the specified type. - Throws:
IllegalArgumentException
- if the values are not convertible to the specified class.
-
contains
public boolean contains(Number value) throws IllegalArgumentException
Returnstrue
if the specified value is within this range.- Parameters:
value
- The value to check for inclusion.- Returns:
true
if the given value is withing this range.- Throws:
IllegalArgumentException
- if the given value is not comparable.
-
contains
public boolean contains(Comparable<?> value) throws IllegalArgumentException
Returnstrue
if the specified value is within this range. The given value must be a subclass ofNumber
.- Overrides:
contains
in classRange<T extends Number & Comparable<? super T>>
- Parameters:
value
- The value to check for inclusion in this range.- Returns:
true
if the given value is included in this range.- Throws:
IllegalArgumentException
- if the given value is not a subclass ofNumber
.
-
contains
public boolean contains(Range<?> range)
Returnstrue
if the supplied range is fully contained within this range.
-
intersects
public boolean intersects(Range<?> range)
Returnstrue
if this range intersects the given range.- Overrides:
intersects
in classRange<T extends Number & Comparable<? super T>>
- Parameters:
range
- The range to check for intersection with this range.- Returns:
true
if the given range intersects this range.- See Also:
Range.intersects(javax.media.jai.util.Range)
-
union
public NumberRange<?> union(Range<?> range)
Returns the union of this range with the given range. Widening conversions will be applied as needed.
-
intersect
public NumberRange<?> intersect(Range<?> range)
Returns the intersection of this range with the given range. Widening conversions will be applied as needed.
-
subtract
public NumberRange<?>[] subtract(Range<?> range)
Returns the range of values that are in this range but not in the given range.
-
getMinimum
public double getMinimum()
Returns the minimum value as adouble
. If this range is unbounded, thenDouble.NEGATIVE_INFINITY
is returned.- Returns:
- The minimum value.
-
getMinimum
public double getMinimum(boolean inclusive)
Returns the minimum value with the specified inclusive or exclusive state. If this range is unbounded, thenDouble.NEGATIVE_INFINITY
is returned.- Parameters:
inclusive
-true
for the minimum value inclusive, orfalse
for the minimum value exclusive.- Returns:
- The minimum value, inclusive or exclusive as requested.
-
getMaximum
public double getMaximum()
Returns the maximum value as adouble
. If this range is unbounded, thenDouble.POSITIVE_INFINITY
is returned.- Returns:
- The maximum value.
-
getMaximum
public double getMaximum(boolean inclusive)
Returns the maximum value with the specified inclusive or exclusive state. If this range is unbounded, thenDouble.POSITIVE_INFINITY
is returned.- Parameters:
inclusive
-true
for the maximum value inclusive, orfalse
for the maximum value exclusive.- Returns:
- The maximum value, inclusive or exclusive as requested.
-
-