E - the type of range elements as a subclass of Number.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. |
static MeasurementRange<Double> |
createGreaterThan(double minValue,
Unit<?> unit)
Constructs a range of
double values greater than the given value. |
boolean |
equals(Object object)
Compares this range with the specified object for equality.
|
int |
hashCode()
Returns a hash code value for this measurement 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. |
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, createLeftBounded, getMaxDouble, getMaxDouble, getMinDouble, getMinDouble, intersectAny, intersectsAny, subtractAny, unionAnycontains, formatTo, getElementType, getMaxValue, getMinValue, isEmpty, isMaxIncluded, isMinIncluded, toStringpublic 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.
This method may return a shared instance, at implementation choice.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.
This method may return a shared instance, at implementation choice.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<Double> createGreaterThan(double minValue, Unit<?> unit)
double values greater than the given value.
The minValue is often zero for creating a range of strictly positive values.
This method may return a shared instance, at implementation choice.minValue - the minimal value (exclusive), or Double.NEGATIVE_INFINITY if none.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.
This method may return a shared instance, at implementation choice.
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 IncommensurableException
targetUnit - the target unit, or null for keeping the unit unchanged.this if no conversion is needed.IncommensurableException - 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 - if 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 - if 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 - if 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 - if 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 - if the given range is an instance of
MeasurementRange using incommensurable unit of measurement.public boolean equals(Object object)
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.