org.geotools.util
Class NumberRange<T extends java.lang.Number & java.lang.Comparable<? super T>>

java.lang.Object
  extended by org.geotools.util.Range<T>
      extended by org.geotools.util.NumberRange<T>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MeasurementRange

public class NumberRange<T extends java.lang.Number & java.lang.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
Version:
$Id: NumberRange.java 30792 2008-06-23 19:19:58Z desruisseaux $
Author:
Martin Desruisseaux (IRD)
See Also:
Serialized Form

Constructor Summary
NumberRange(byte minimum, boolean isMinIncluded, byte maximum, boolean isMaxIncluded)
          Deprecated. Use create method instead.
NumberRange(byte minimum, byte maximum)
          Deprecated. Use create method instead.
NumberRange(java.lang.Class<T> type, T minimum, boolean isMinIncluded, T maximum, boolean isMaxIncluded)
          Constructs a range of Number objects.
NumberRange(java.lang.Class<T> type, T minimum, T maximum)
          Constructs an inclusive range of Number objects.
NumberRange(double minimum, boolean isMinIncluded, double maximum, boolean isMaxIncluded)
          Deprecated. Use create method instead.
NumberRange(double minimum, double maximum)
          Deprecated. Use create method instead.
NumberRange(float minimum, boolean isMinIncluded, float maximum, boolean isMaxIncluded)
          Deprecated. Use create method instead.
NumberRange(float minimum, float maximum)
          Deprecated. Use create method instead.
NumberRange(int minimum, boolean isMinIncluded, int maximum, boolean isMaxIncluded)
          Deprecated. Use create method instead.
NumberRange(int minimum, int maximum)
          Deprecated. Use create method instead.
NumberRange(long minimum, boolean isMinIncluded, long maximum, boolean isMaxIncluded)
          Deprecated. Use create method instead.
NumberRange(long minimum, long maximum)
          Deprecated. Use create method instead.
NumberRange(Range<T> range)
          Constructs a range with the same type and the same values than the specified range.
NumberRange(short minimum, boolean isMinIncluded, short maximum, boolean isMaxIncluded)
          Deprecated. Use create method instead.
NumberRange(short minimum, short maximum)
          Deprecated. Use create method instead.
 
Method Summary
<N extends java.lang.Number & java.lang.Comparable<? super N>>
NumberRange<N>
castTo(java.lang.Class<N> type)
          Casts this range to the specified type.
 boolean contains(java.lang.Comparable<?> value)
          Returns true if the specified value is within this range.
 boolean contains(java.lang.Number value)
          Returns true if the specified value is within this range.
 boolean contains(Range<?> range)
          Returns true if the supplied range is fully contained within this range.
static NumberRange<java.lang.Byte> create(byte minimum, boolean isMinIncluded, byte maximum, boolean isMaxIncluded)
          Constructs a range of byte values.
static NumberRange<java.lang.Byte> create(byte minimum, byte maximum)
          Constructs an inclusive range of byte values.
static NumberRange<java.lang.Double> create(double minimum, boolean isMinIncluded, double maximum, boolean isMaxIncluded)
          Constructs a range of double values.
static NumberRange<java.lang.Double> create(double minimum, double maximum)
          Constructs an inclusive range of double values.
static NumberRange<java.lang.Float> create(float minimum, boolean isMinIncluded, float maximum, boolean isMaxIncluded)
          Constructs a range of float values.
static NumberRange<java.lang.Float> create(float minimum, float maximum)
          Constructs an inclusive range of float values.
static NumberRange<java.lang.Integer> create(int minimum, boolean isMinIncluded, int maximum, boolean isMaxIncluded)
          Constructs a range of int values.
static NumberRange<java.lang.Integer> create(int minimum, int maximum)
          Constructs an inclusive range of int values.
static NumberRange<java.lang.Long> create(long minimum, boolean isMinIncluded, long maximum, boolean isMaxIncluded)
          Constructs a range of long values.
static NumberRange<java.lang.Long> create(long minimum, long maximum)
          Constructs an inclusive range of long values.
static NumberRange<java.lang.Short> create(short minimum, boolean isMinIncluded, short maximum, boolean isMaxIncluded)
          Constructs a range of short values.
static NumberRange<java.lang.Short> create(short minimum, short maximum)
          Constructs an inclusive range of short values.
 double getMaximum()
          Returns the maximum value as a double.
 double getMaximum(boolean inclusive)
          Returns the maximum value with the specified inclusive or exclusive state.
 double getMinimum()
          Returns the minimum value as a double.
 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)
          Returns true 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 java.lang.Number & java.lang.Comparable<? super N>>
NumberRange<N>
wrap(Range<N> range)
          Wraps the specified Range in a NumberRange object.
 
Methods inherited from class org.geotools.util.Range
equals, getElementClass, getMaxValue, getMinValue, hashCode, isEmpty, isMaxIncluded, isMinIncluded, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberRange

public NumberRange(byte minimum,
                   byte maximum)
Deprecated. Use create method instead.


NumberRange

@Deprecated
public NumberRange(byte minimum,
                              boolean isMinIncluded,
                              byte maximum,
                              boolean isMaxIncluded)
Deprecated. Use create method instead.


NumberRange

public NumberRange(short minimum,
                   short maximum)
Deprecated. Use create method instead.


NumberRange

@Deprecated
public NumberRange(short minimum,
                              boolean isMinIncluded,
                              short maximum,
                              boolean isMaxIncluded)
Deprecated. Use create method instead.


NumberRange

public NumberRange(int minimum,
                   int maximum)
Deprecated. Use create method instead.


NumberRange

@Deprecated
public NumberRange(int minimum,
                              boolean isMinIncluded,
                              int maximum,
                              boolean isMaxIncluded)
Deprecated. Use create method instead.


NumberRange

public NumberRange(long minimum,
                   long maximum)
Deprecated. Use create method instead.


NumberRange

@Deprecated
public NumberRange(long minimum,
                              boolean isMinIncluded,
                              long maximum,
                              boolean isMaxIncluded)
Deprecated. Use create method instead.


NumberRange

public NumberRange(float minimum,
                   float maximum)
Deprecated. Use create method instead.


NumberRange

@Deprecated
public NumberRange(float minimum,
                              boolean isMinIncluded,
                              float maximum,
                              boolean isMaxIncluded)
Deprecated. Use create method instead.


NumberRange

public NumberRange(double minimum,
                   double maximum)
Deprecated. Use create method instead.


NumberRange

@Deprecated
public NumberRange(double minimum,
                              boolean isMinIncluded,
                              double maximum,
                              boolean isMaxIncluded)
Deprecated. Use create method instead.


NumberRange

public NumberRange(java.lang.Class<T> type,
                   T minimum,
                   T maximum)
Constructs an inclusive range of Number objects.

Parameters:
type - The element class, usually one of Byte, Short, Integer, Long, Float or Double.
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.

NumberRange

public NumberRange(java.lang.Class<T> type,
                   T minimum,
                   boolean isMinIncluded,
                   T maximum,
                   boolean isMaxIncluded)
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.

NumberRange

public NumberRange(Range<T> range)
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 be Number instances.
Since:
2.4
Method Detail

create

public static NumberRange<java.lang.Byte> create(byte minimum,
                                                 byte maximum)
Constructs an inclusive range of byte values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
Since:
2.5

create

public static NumberRange<java.lang.Byte> create(byte minimum,
                                                 boolean isMinIncluded,
                                                 byte maximum,
                                                 boolean isMaxIncluded)
Constructs a range of byte 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<java.lang.Short> create(short minimum,
                                                  short maximum)
Constructs an inclusive range of short values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
Since:
2.5

create

public static NumberRange<java.lang.Short> create(short minimum,
                                                  boolean isMinIncluded,
                                                  short maximum,
                                                  boolean isMaxIncluded)
Constructs a range of short 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<java.lang.Integer> create(int minimum,
                                                    int maximum)
Constructs an inclusive range of int values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
Since:
2.5

create

public static NumberRange<java.lang.Integer> create(int minimum,
                                                    boolean isMinIncluded,
                                                    int maximum,
                                                    boolean isMaxIncluded)
Constructs a range of int 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<java.lang.Long> create(long minimum,
                                                 long maximum)
Constructs an inclusive range of long values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
Since:
2.5

create

public static NumberRange<java.lang.Long> create(long minimum,
                                                 boolean isMinIncluded,
                                                 long maximum,
                                                 boolean isMaxIncluded)
Constructs a range of long 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<java.lang.Float> create(float minimum,
                                                  float maximum)
Constructs an inclusive range of float values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
Since:
2.5

create

public static NumberRange<java.lang.Float> create(float minimum,
                                                  boolean isMinIncluded,
                                                  float maximum,
                                                  boolean isMaxIncluded)
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.
Since:
2.5

create

public static NumberRange<java.lang.Double> create(double minimum,
                                                   double maximum)
Constructs an inclusive range of double values.

Parameters:
minimum - The minimum value, inclusive.
maximum - The maximum value, inclusive.
Since:
2.5

create

public static NumberRange<java.lang.Double> create(double minimum,
                                                   boolean isMinIncluded,
                                                   double maximum,
                                                   boolean isMaxIncluded)
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.
Since:
2.5

wrap

public static <N extends java.lang.Number & java.lang.Comparable<? super N>> NumberRange<N> wrap(Range<N> range)
Wraps the specified Range in a NumberRange object. If the specified range is already an instance of NumberRange, 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 a NumberRange object.

castTo

public <N extends java.lang.Number & java.lang.Comparable<? super N>> NumberRange<N> castTo(java.lang.Class<N> type)
                                                                                throws java.lang.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 of Byte, Short, Integer, Long, Float or Double.
Returns:
The casted range, or this if this range already uses the specified type.
Throws:
java.lang.IllegalArgumentException - if the values are not convertible to the specified class.

contains

public boolean contains(java.lang.Number value)
                 throws java.lang.IllegalArgumentException
Returns true 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:
java.lang.IllegalArgumentException - if the given value is not comparable.

contains

public boolean contains(java.lang.Comparable<?> value)
                 throws java.lang.IllegalArgumentException
Returns true if the specified value is within this range. The given value must be a subclass of Number.

Overrides:
contains in class Range<T extends java.lang.Number & java.lang.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:
java.lang.IllegalArgumentException - if the given value is not a subclass of Number.

contains

public boolean contains(Range<?> range)
Returns true if the supplied range is fully contained within this range.

Overrides:
contains in class Range<T extends java.lang.Number & java.lang.Comparable<? super T>>
Parameters:
range - The range to check for inclusion in this range.
Returns:
true if the given range is included in this range.

intersects

public boolean intersects(Range<?> range)
Returns true if this range intersects the given range.

Overrides:
intersects in class Range<T extends java.lang.Number & java.lang.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.

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

intersect

public NumberRange<?> intersect(Range<?> range)
Returns the intersection of this range with the given range. Widening conversions will be applied as needed.

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

subtract

public NumberRange<?>[] subtract(Range<?> range)
Returns the range of values that are in this range but not in the given range.

Overrides:
subtract in class Range<T extends java.lang.Number & java.lang.Comparable<? super T>>
Parameters:
range - The range to substract.
Returns:
This range without the given range.
See Also:
Range.subtract(javax.media.jai.util.Range)

getMinimum

public double getMinimum()
Returns the minimum value as a double. If this range is unbounded, then Double.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, then Double.NEGATIVE_INFINITY is returned.

Parameters:
inclusive - true for the minimum value inclusive, or false for the minimum value exclusive.
Returns:
The minimum value, inclusive or exclusive as requested.

getMaximum

public double getMaximum()
Returns the maximum value as a double. If this range is unbounded, then Double.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, then Double.POSITIVE_INFINITY is returned.

Parameters:
inclusive - true for the maximum value inclusive, or false for the maximum value exclusive.
Returns:
The maximum value, inclusive or exclusive as requested.


Copyright © 1996-2010 Geotools. All Rights Reserved.