E
- The type of range elements as a subclass of Number
.@Immutable public class MeasurementRange<E extends Number & Comparable<? super E>> extends NumberRange<E>
this
range object - values of the range
object given in argument are converted if needed before an operation is applied.
Other methods defined in this class:
create(…)
static methods for every floating point primitive types.
Usage of MeasurementRange
with integer types is possible, but no convenience
method is provided for integers because they are usually not representative of the
nature of physical measurements.convertTo(Unit)
for converting the unit of measurement.castTo(Class)
for casting the range values to an other type.RangeFormat
,
RangeSet
,
Serialized FormDefined in the sis-utility module
Constructor and Description |
---|
MeasurementRange(Class<E> type,
E minValue,
boolean isMinIncluded,
E maxValue,
boolean isMaxIncluded,
Unit<?> unit)
Constructs a range of
Number objects. |
MeasurementRange(Class<E> type,
ValueRange range,
Unit<?> unit)
Constructs a range of the given type with values from the given annotation.
|
MeasurementRange(Range<E> range,
Unit<?> unit)
Constructs a range with the same values than the specified range and the given unit.
|
Modifier and Type | Method and Description |
---|---|
<N extends Number & Comparable<? super N>> |
castTo(Class<N> type)
Casts this range to the specified type.
|
boolean |
contains(Range<? extends E> range)
Returns
true if the supplied range is fully contained within this range. |
MeasurementRange<E> |
convertTo(Unit<?> targetUnit)
Converts this range to the specified unit.
|
static MeasurementRange<Double> |
create(double minValue,
boolean isMinIncluded,
double maxValue,
boolean isMaxIncluded,
Unit<?> unit)
Constructs a range of
double values. |
static MeasurementRange<Float> |
create(float minValue,
boolean isMinIncluded,
float maxValue,
boolean isMaxIncluded,
Unit<?> unit)
Constructs a range of
float values. |
static MeasurementRange<?> |
createBestFit(Number minValue,
boolean isMinIncluded,
Number maxValue,
boolean isMaxIncluded,
Unit<?> unit)
Constructs a range using the smallest type of
Number that can hold the given values. |
boolean |
equals(Object object)
Compares this range with the specified object for equality.
|
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. |
Range<E>[] |
subtract(Range<E> range)
Returns the range of values that are in this range but not in the given range.
|
Range<E> |
union(Range<E> range)
Returns the union of this range with the given range.
|
Unit<?> |
unit()
Returns the unit of measurement, or
null if unknown. |
castOrCopy, containsAny, containsAny, create, create, create, create, create, create, createBestFit, getMaxDouble, getMaxDouble, getMinDouble, getMinDouble, intersectAny, intersectsAny, subtractAny, unionAny
contains, formatTo, getElementType, getMaxValue, getMinValue, hashCode, isEmpty, isMaxIncluded, isMinIncluded, toString
public MeasurementRange(Range<E> range, Unit<?> unit)
range
- The range to copy. The elements must be Number
instances.unit
- The unit of measurement, or null
if unknown.public MeasurementRange(Class<E> type, ValueRange range, Unit<?> unit) throws IllegalArgumentException
public MeasurementRange(Class<E> type, E minValue, boolean isMinIncluded, E maxValue, boolean isMaxIncluded, Unit<?> unit)
Number
objects.type
- The element type, usually one of Float
or Double
.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.unit
- The unit of measurement, or null
if unknown.public static MeasurementRange<Float> create(float minValue, boolean isMinIncluded, float maxValue, boolean isMaxIncluded, Unit<?> unit)
float
values.minValue
- The minimal value, or Float.NEGATIVE_INFINITY
if none.isMinIncluded
- true
if the minimal value is inclusive, or false
if exclusive.maxValue
- The maximal value, or Float.POSITIVE_INFINITY
if none.isMaxIncluded
- true
if the maximal value is inclusive, or false
if exclusive.unit
- The unit of measurement, or null
if unknown.public static MeasurementRange<Double> create(double minValue, boolean isMinIncluded, double maxValue, boolean isMaxIncluded, Unit<?> unit)
double
values.minValue
- The minimal value, or Double.NEGATIVE_INFINITY
if none.isMinIncluded
- true
if the minimal value is inclusive, or false
if exclusive.maxValue
- The maximal value, or Double.POSITIVE_INFINITY
if none.isMaxIncluded
- true
if the maximal value is inclusive, or false
if exclusive.unit
- The unit of measurement, or null
if unknown.public static MeasurementRange<?> createBestFit(Number minValue, boolean isMinIncluded, Number maxValue, boolean isMaxIncluded, Unit<?> unit)
Number
that can hold the given values.
This method performs the same work than NumberRange.createBestFit(…)
with an additional unit
argument.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.unit
- The unit of measurement, or null
if unknown.null
if both minValue
and maxValue
are null
.NumberRange.createBestFit(Number, boolean, Number, boolean)
public Unit<?> unit()
null
if unknown.null
.public MeasurementRange<E> convertTo(Unit<?> targetUnit) throws ConversionException
targetUnit
- the target unit, or null
for keeping the unit unchanged.this
if no conversion is needed.ConversionException
- if the target unit are not compatible with
this range unit.public <N extends Number & Comparable<? super N>> MeasurementRange<N> castTo(Class<N> type)
castTo
in class NumberRange<E extends Number & Comparable<? super E>>
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.public boolean contains(Range<? extends E> range) throws IllegalArgumentException
true
if the supplied range is fully contained within this range.
If the given range is an instance of MeasurementRange
, then this method converts
the value of the other range to the unit of measurement of this range before to perform
the operation.contains
in class Range<E extends Number & Comparable<? super E>>
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 an instance of
MeasurementRange
using incommensurable unit of measurement.public boolean intersects(Range<? extends E> range) throws IllegalArgumentException
true
if this range intersects the given range.
If the given range is an instance of MeasurementRange
, then this method converts
the value of the other range to the unit of measurement of this range before to perform
the operation.intersects
in class Range<E extends Number & Comparable<? super E>>
range
- The range to check for intersection with this range.true
if the given range intersects this range.IllegalArgumentException
- is the given range is an instance of
MeasurementRange
using incommensurable unit of measurement.public Range<E> intersect(Range<E> range) throws IllegalArgumentException
MeasurementRange
, then this method converts
the value of the other range to the unit of measurement of this range before to perform
the operation.intersect
in class Range<E extends Number & Comparable<? super E>>
range
- The range to intersect.IllegalArgumentException
- is the given range is an instance of
MeasurementRange
using incommensurable unit of measurement.public Range<E> union(Range<E> range) throws IllegalArgumentException
MeasurementRange
, then this method converts
the value of the other range to the unit of measurement of this range before to perform
the operation.union
in class Range<E extends Number & Comparable<? super E>>
range
- The range to add to this range.IllegalArgumentException
- is the given range is an instance of
MeasurementRange
using incommensurable unit of measurement.public Range<E>[] subtract(Range<E> range) throws IllegalArgumentException
MeasurementRange
, then this method converts
the value of the other range to the unit of measurement of this range before to perform
the operation.subtract
in class Range<E extends Number & Comparable<? super E>>
range
- The range to subtract.IllegalArgumentException
- is the given range is an instance of
MeasurementRange
using incommensurable unit of measurement.public boolean equals(Object object)
Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.