Package org.geotools.util
Class NumberRange<T extends Number & Comparable<? super T>>
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MeasurementRange
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:
-
Constructor Summary
ConstructorsConstructorDescriptionNumberRange(Class<T> type, T minimum, boolean isMinIncluded, T maximum, boolean isMaxIncluded) Constructs a range ofNumberobjects.NumberRange(Class<T> type, T minimum, T maximum) Constructs an inclusive range ofNumberobjects.NumberRange(Range<T> range) Constructs a range with the same type and the same values than the specified range. -
Method Summary
Modifier and TypeMethodDescription<N extends Number & Comparable<? super N>>
NumberRange<N>Casts this range to the specified type.booleancontains(Comparable<?> value) Returnstrueif the specified value is within this range.booleanReturnstrueif the specified value is within this range.booleanReturnstrueif the supplied range is fully contained within this range.static NumberRange<Byte>create(byte minimum, boolean isMinIncluded, byte maximum, boolean isMaxIncluded) Constructs a range ofbytevalues.static NumberRange<Byte>create(byte minimum, byte maximum) Constructs an inclusive range ofbytevalues.static NumberRange<Double>create(double minimum, boolean isMinIncluded, double maximum, boolean isMaxIncluded) Constructs a range ofdoublevalues.static NumberRange<Double>create(double minimum, double maximum) Constructs an inclusive range ofdoublevalues.static NumberRange<Float>create(float minimum, boolean isMinIncluded, float maximum, boolean isMaxIncluded) Constructs a range offloatvalues.static NumberRange<Float>create(float minimum, float maximum) Constructs an inclusive range offloatvalues.static NumberRange<Integer>create(int minimum, boolean isMinIncluded, int maximum, boolean isMaxIncluded) Constructs a range ofintvalues.static NumberRange<Integer>create(int minimum, int maximum) Constructs an inclusive range ofintvalues.static NumberRange<Long>create(long minimum, boolean isMinIncluded, long maximum, boolean isMaxIncluded) Constructs a range oflongvalues.static NumberRange<Long>create(long minimum, long maximum) Constructs an inclusive range oflongvalues.static NumberRange<Short>create(short minimum, boolean isMinIncluded, short maximum, boolean isMaxIncluded) Constructs a range ofshortvalues.static NumberRange<Short>create(short minimum, short maximum) Constructs an inclusive range ofshortvalues.doubleReturns the maximum value as adouble.doublegetMaximum(boolean inclusive) Returns the maximum value with the specified inclusive or exclusive state.doubleReturns the minimum value as adouble.doublegetMinimum(boolean inclusive) Returns the minimum value with the specified inclusive or exclusive state.NumberRange<?>Returns the intersection of this range with the given range.booleanintersects(Range<?> range) Returnstrueif this range intersects the given range.NumberRange<?>[]Returns the range of values that are in this range but not in the given range.NumberRange<?>Returns the union of this range with the given range.static <N extends Number & Comparable<? super N>>
NumberRange<N>Wraps the specifiedRangein aNumberRangeobject.Methods inherited from class Range
equals, getElementClass, getMaxValue, getMinValue, hashCode, isEmpty, isMaxIncluded, isMinIncluded, toString
-
Constructor Details
-
NumberRange
Constructs an inclusive range ofNumberobjects. -
NumberRange
public NumberRange(Class<T> type, T minimum, boolean isMinIncluded, T maximum, boolean isMaxIncluded) Constructs a range ofNumberobjects.- Parameters:
type- The element class, usually one ofByte,Short,Integer,Long,FloatorDouble.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.
-
NumberRange
Constructs a range with the same type and the same values than the specified range. This is a copy constructor.- Parameters:
range- The range to copy. The elements must beNumberinstances.- Since:
- 2.4
-
-
Method Details
-
create
Constructs an inclusive range ofbytevalues.- 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 ofbytevalues.- 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
Constructs an inclusive range ofshortvalues.- 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 ofshortvalues.- 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
Constructs an inclusive range ofintvalues.- 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 ofintvalues.- 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
Constructs an inclusive range oflongvalues.- 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 oflongvalues.- 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
Constructs an inclusive range offloatvalues.- 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 offloatvalues.- 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
Constructs an inclusive range ofdoublevalues.- 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 ofdoublevalues.- 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
Wraps the specifiedRangein aNumberRangeobject. 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
rangeas aNumberRangeobject.
-
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,FloatorDouble.- Returns:
- The casted range, or
thisif this range already uses the specified type. - Throws:
IllegalArgumentException- if the values are not convertible to the specified class.
-
contains
Returnstrueif the specified value is within this range.- Parameters:
value- The value to check for inclusion.- Returns:
trueif the given value is withing this range.- Throws:
IllegalArgumentException- if the given value is not comparable.
-
contains
Returnstrueif the specified value is within this range. The given value must be a subclass ofNumber.- Overrides:
containsin classRange<T extends Number & Comparable<? super T>>- Parameters:
value- The value to check for inclusion in this range.- Returns:
trueif the given value is included in this range.- Throws:
IllegalArgumentException- if the given value is not a subclass ofNumber.
-
contains
Returnstrueif the supplied range is fully contained within this range. -
intersects
Returnstrueif this range intersects the given range.- Overrides:
intersectsin classRange<T extends Number & Comparable<? super T>>- Parameters:
range- The range to check for intersection with this range.- Returns:
trueif the given range intersects this range.- See Also:
-
Range.intersects(org.eclipse.imagen.util.Range)
-
union
Returns the union of this range with the given range. Widening conversions will be applied as needed. -
intersect
Returns the intersection of this range with the given range. Widening conversions will be applied as needed. -
subtract
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_INFINITYis 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_INFINITYis returned.- Parameters:
inclusive-truefor the minimum value inclusive, orfalsefor 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_INFINITYis 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_INFINITYis returned.- Parameters:
inclusive-truefor the maximum value inclusive, orfalsefor the maximum value exclusive.- Returns:
- The maximum value, inclusive or exclusive as requested.
-