org.geotoolkit.util
Class MeasurementRange<T extends Number & Comparable<? super T>>

Object
  extended by Range<T>
      extended by NumberRange<T>
          extended by MeasurementRange<T>
Type Parameters:
T - The type of range elements as a subclass of Number.
All Implemented Interfaces:
Serializable

@Immutable
public class MeasurementRange<T extends Number & Comparable<? super T>>
extends NumberRange<T>

A range of numbers associated with a unit of measurement. Unit conversions are applied as needed by union and intersection operations.

Since:
2.4
Version:
3.09
Author:
Martin Desruisseaux (Geomatys)
See Also:
org.geotoolkit.measure, RangeFormat, Serialized Form
Module:
utility/geotk-utility (download)    View source code for this class

Constructor Summary
MeasurementRange(Class<T> type, T minimum, boolean isMinIncluded, T maximum, boolean isMaxIncluded, Unit<?> units)
          Constructs a range of Number objects.
MeasurementRange(Range<T> range, Unit<?> units)
          Constructs a range with the same values than the specified range.
 
Method Summary
<N extends Number & Comparable<? super N>>
MeasurementRange<N>
castTo(Class<N> type)
          Casts this range to the specified type.
 MeasurementRange<T> convertTo(Unit<?> targetUnits)
          Converts this range to the specified units.
static MeasurementRange<Double> create(double minimum, boolean isMinIncluded, double maximum, boolean isMaxIncluded, Unit<?> units)
          Constructs a range of double values.
static MeasurementRange<Double> create(double minimum, double maximum, Unit<?> units)
          Constructs an inclusive range of double values.
static MeasurementRange<Float> create(float minimum, boolean isMinIncluded, float maximum, boolean isMaxIncluded, Unit<?> units)
          Constructs a range of float values.
static MeasurementRange<Float> create(float minimum, float maximum, Unit<?> units)
          Constructs an inclusive range of float values.
static MeasurementRange<?> createBestFit(Number minimum, boolean isMinIncluded, Number maximum, boolean isMaxIncluded, Unit<?> units)
          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.
 Unit<?> getUnits()
          Returns the units of measurement, or null if unknown.
 MeasurementRange<?> intersect(Range<?> range)
          Returns the intersection between this range and the provided range.
 MeasurementRange<?>[] subtract(Range<?> range)
          Returns the range of values that are in this range but not in the given range.
 MeasurementRange<?> union(Range<?> range)
          Returns the union of this range with the given range.
 
Methods inherited from class NumberRange
contains, contains, contains, create, create, create, create, create, create, create, create, create, create, create, create, createBestFit, getMaximum, getMaximum, getMinimum, getMinimum, intersects, wrap
 
Methods inherited from class Range
getElementClass, getMaxValue, getMinValue, hashCode, isEmpty, isMaxIncluded, isMinIncluded, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MeasurementRange

public MeasurementRange(Class<T> type,
                        T minimum,
                        boolean isMinIncluded,
                        T maximum,
                        boolean isMaxIncluded,
                        Unit<?> units)
Constructs a range of Number objects.

Parameters:
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.
units - The units of measurement, or null if unknown.

MeasurementRange

public MeasurementRange(Range<T> range,
                        Unit<?> units)
Constructs a range with the same values than the specified range.

Parameters:
range - The range to copy. The elements must be Number instances.
units - The units of measurement, or null if unknown.
Method Detail

create

public static MeasurementRange<Float> create(float minimum,
                                             float maximum,
                                             Unit<?> units)
Constructs an inclusive range of float values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
units - The units of measurement, or null if unknown.
Returns:
The measurement range.
Since:
2.5

create

public static MeasurementRange<Float> create(float minimum,
                                             boolean isMinIncluded,
                                             float maximum,
                                             boolean isMaxIncluded,
                                             Unit<?> units)
Constructs a range of float 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.
units - The units of measurement, or null if unknown.
Returns:
The measurement range.
Since:
2.5

create

public static MeasurementRange<Double> create(double minimum,
                                              double maximum,
                                              Unit<?> units)
Constructs an inclusive range of double values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
units - The units of measurement, or null if unknown.
Returns:
The measurement range.

create

public static MeasurementRange<Double> create(double minimum,
                                              boolean isMinIncluded,
                                              double maximum,
                                              boolean isMaxIncluded,
                                              Unit<?> units)
Constructs a range of double 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.
units - The units of measurement, or null if unknown.
Returns:
The measurement range.

createBestFit

public static MeasurementRange<?> createBestFit(Number minimum,
                                                boolean isMinIncluded,
                                                Number maximum,
                                                boolean isMaxIncluded,
                                                Unit<?> units)
Constructs a range using the smallest type of Number that can hold the given values. This method performs the same work than NumberRange.createBestFit(...) with an additional units argument.

Parameters:
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.
units - The units of measurement, or null if unknown.
Returns:
The new range, or null if both minimum and maximum are null.
Since:
3.09
See Also:
NumberRange.createBestFit(Number, boolean, Number, boolean)

getUnits

public Unit<?> getUnits()
Returns the units of measurement, or null if unknown.

Returns:
The units of measurement, or null.

convertTo

public MeasurementRange<T> convertTo(Unit<?> targetUnits)
                                                                    throws ConversionException
Converts this range to the specified units. If this measurement range has null units, then the specified target units are simply assigned to the returned range with no other changes.

Parameters:
targetUnits - the target units, or null for keeping the units unchanged.
Returns:
The converted range, or this if no conversion is needed.
Throws:
ConversionException - if the target units are not compatible with this range units.

castTo

public <N extends Number & Comparable<? super N>> MeasurementRange<N> castTo(Class<N> type)
Casts this range to the specified type.

Overrides:
castTo in class NumberRange<T extends Number & Comparable<? super T>>
Type Parameters:
N - The class to cast to.
Parameters:
type - The class to cast to. Must be one of Byte, Short, Integer, Long, Float or Double.
Returns:
The casted range, or this if this range already uses the specified type.

union

public MeasurementRange<?> union(Range<?> range)
                          throws IllegalArgumentException
Returns the union of this range with the given range. Widening conversions will be applied as needed.

Overrides:
union in class NumberRange<T extends Number & Comparable<? super T>>
Parameters:
range - The range to add to this range.
Returns:
The union of this range with the given range.
Throws:
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.
See Also:
Range.union(javax.media.jai.util.Range)

intersect

public MeasurementRange<?> intersect(Range<?> range)
                              throws IllegalArgumentException
Returns the intersection between this range and the provided range. Widening conversions will be applied as needed.

Overrides:
intersect in class NumberRange<T extends Number & Comparable<? super T>>
Parameters:
range - The range to intersect.
Returns:
The intersection of this range with the provided range.
Throws:
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.
See Also:
Range.intersect(javax.media.jai.util.Range)

subtract

public MeasurementRange<?>[] subtract(Range<?> range)
                               throws IllegalArgumentException
Returns the range of values that are in this range but not in the given range. This method returns an array of length 0, 1 or 2:

Overrides:
subtract in class NumberRange<T extends Number & Comparable<? super T>>
Parameters:
range - The range to subtract.
Returns:
This range without the given range.
Throws:
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.
See Also:
Range.subtract(javax.media.jai.util.Range)

equals

public boolean equals(Object object)
Compares this range with the specified object for equality.

Overrides:
equals in class Range<T extends Number & Comparable<? super T>>
Parameters:
object - The object to compare with this range for equality.
Returns:
true if the given object is equal to this range.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.