Class Range
- java.lang.Object
-
- org.apache.commons.lang.math.Range
-
- Direct Known Subclasses:
DoubleRange
,FloatRange
,IntRange
,LongRange
,NumberRange
public abstract class Range extends Object
Range
represents a range of numbers of the same type.Specific subclasses hold the range values as different types. Each subclass should be immutable and
Serializable
if possible.- Since:
- 2.0
- Version:
- $Id: Range.java 1057072 2011-01-10 01:55:57Z niallp $
-
-
Constructor Summary
Constructors Constructor Description Range()
Constructs a new range.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
containsDouble(double value)
Tests whether the specifieddouble
occurs within this range usingdouble
comparison.boolean
containsDouble(Number value)
Tests whether the specifiedNumber
occurs within this range usingdouble
comparison..boolean
containsFloat(float value)
Tests whether the specifiedfloat
occurs within this range usingfloat
comparison.boolean
containsFloat(Number value)
Tests whether the specifiedNumber
occurs within this range usingfloat
comparison.boolean
containsInteger(int value)
Tests whether the specifiedint
occurs within this range usingint
comparison.boolean
containsInteger(Number value)
Tests whether the specifiedNumber
occurs within this range usingint
comparison..boolean
containsLong(long value)
Tests whether the specifiedlong
occurs within this range usinglong
comparison.boolean
containsLong(Number value)
Tests whether the specifiedNumber
occurs within this range usinglong
comparison..abstract boolean
containsNumber(Number number)
Tests whether the specifiedNumber
occurs within this range.boolean
containsRange(Range range)
Tests whether the specified range occurs entirely within this range.boolean
equals(Object obj)
Compares this range to another object to test if they are equal.double
getMaximumDouble()
Gets the maximum number in this range as adouble
.float
getMaximumFloat()
Gets the maximum number in this range as afloat
.int
getMaximumInteger()
Gets the maximum number in this range as aint
.long
getMaximumLong()
Gets the maximum number in this range as along
.abstract Number
getMaximumNumber()
Gets the maximum number in this range.double
getMinimumDouble()
Gets the minimum number in this range as adouble
.float
getMinimumFloat()
Gets the minimum number in this range as afloat
.int
getMinimumInteger()
Gets the minimum number in this range as aint
.long
getMinimumLong()
Gets the minimum number in this range as along
.abstract Number
getMinimumNumber()
Gets the minimum number in this range.int
hashCode()
Gets a hashCode for the range.boolean
overlapsRange(Range range)
Tests whether the specified range overlaps with this range.String
toString()
Gets the range as aString
.
-
-
-
Method Detail
-
getMinimumNumber
public abstract Number getMinimumNumber()
Gets the minimum number in this range.
- Returns:
- the minimum number in this range
-
getMinimumLong
public long getMinimumLong()
Gets the minimum number in this range as a
long
.This implementation uses the
getMinimumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMinimumInteger
public int getMinimumInteger()
Gets the minimum number in this range as a
int
.This implementation uses the
getMinimumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMinimumDouble
public double getMinimumDouble()
Gets the minimum number in this range as a
double
.This implementation uses the
getMinimumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMinimumFloat
public float getMinimumFloat()
Gets the minimum number in this range as a
float
.This implementation uses the
getMinimumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMaximumNumber
public abstract Number getMaximumNumber()
Gets the maximum number in this range.
- Returns:
- the maximum number in this range
-
getMaximumLong
public long getMaximumLong()
Gets the maximum number in this range as a
long
.This implementation uses the
getMaximumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
getMaximumInteger
public int getMaximumInteger()
Gets the maximum number in this range as a
int
.This implementation uses the
getMaximumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
getMaximumDouble
public double getMaximumDouble()
Gets the maximum number in this range as a
double
.This implementation uses the
getMaximumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
getMaximumFloat
public float getMaximumFloat()
Gets the maximum number in this range as a
float
.This implementation uses the
getMaximumNumber()
method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
containsNumber
public abstract boolean containsNumber(Number number)
Tests whether the specified
Number
occurs within this range.The exact comparison implementation varies by subclass. It is intended that an
int
specific subclass will compare usingint
comparison.null
is handled and returnsfalse
.- Parameters:
number
- the number to test, may benull
- Returns:
true
if the specified number occurs within this range- Throws:
IllegalArgumentException
- if theNumber
cannot be compared
-
containsLong
public boolean containsLong(Number value)
Tests whether the specified
Number
occurs within this range usinglong
comparison..null
is handled and returnsfalse
.This implementation forwards to the
containsLong(long)
method.- Parameters:
value
- the long to test, may benull
- Returns:
true
if the specified number occurs within this range bylong
comparison
-
containsLong
public boolean containsLong(long value)
Tests whether the specified
long
occurs within this range usinglong
comparison.This implementation uses the
getMinimumLong()
andgetMaximumLong()
methods and should be good for most uses.- Parameters:
value
- the long to test- Returns:
true
if the specified number occurs within this range bylong
comparison
-
containsInteger
public boolean containsInteger(Number value)
Tests whether the specified
Number
occurs within this range usingint
comparison..null
is handled and returnsfalse
.This implementation forwards to the
containsInteger(int)
method.- Parameters:
value
- the integer to test, may benull
- Returns:
true
if the specified number occurs within this range byint
comparison
-
containsInteger
public boolean containsInteger(int value)
Tests whether the specified
int
occurs within this range usingint
comparison.This implementation uses the
getMinimumInteger()
andgetMaximumInteger()
methods and should be good for most uses.- Parameters:
value
- the int to test- Returns:
true
if the specified number occurs within this range byint
comparison
-
containsDouble
public boolean containsDouble(Number value)
Tests whether the specified
Number
occurs within this range usingdouble
comparison..null
is handled and returnsfalse
.This implementation forwards to the
containsDouble(double)
method.- Parameters:
value
- the double to test, may benull
- Returns:
true
if the specified number occurs within this range bydouble
comparison
-
containsDouble
public boolean containsDouble(double value)
Tests whether the specified
double
occurs within this range usingdouble
comparison.This implementation uses the
getMinimumDouble()
andgetMaximumDouble()
methods and should be good for most uses.- Parameters:
value
- the double to test- Returns:
true
if the specified number occurs within this range bydouble
comparison
-
containsFloat
public boolean containsFloat(Number value)
Tests whether the specified
Number
occurs within this range usingfloat
comparison.null
is handled and returnsfalse
.This implementation forwards to the
containsFloat(float)
method.- Parameters:
value
- the float to test, may benull
- Returns:
true
if the specified number occurs within this range byfloat
comparison
-
containsFloat
public boolean containsFloat(float value)
Tests whether the specified
float
occurs within this range usingfloat
comparison.This implementation uses the
getMinimumFloat()
andgetMaximumFloat()
methods and should be good for most uses.- Parameters:
value
- the float to test- Returns:
true
if the specified number occurs within this range byfloat
comparison
-
containsRange
public boolean containsRange(Range range)
Tests whether the specified range occurs entirely within this range.
The exact comparison implementation varies by subclass. It is intended that an
int
specific subclass will compare usingint
comparison.null
is handled and returnsfalse
.This implementation uses the
containsNumber(Number)
method. Subclasses may be able to optimise this.- Parameters:
range
- the range to test, may benull
- Returns:
true
if the specified range occurs entirely within this range; otherwise,false
- Throws:
IllegalArgumentException
- if theRange
cannot be compared
-
overlapsRange
public boolean overlapsRange(Range range)
Tests whether the specified range overlaps with this range.
The exact comparison implementation varies by subclass. It is intended that an
int
specific subclass will compare usingint
comparison.null
is handled and returnsfalse
.This implementation uses the
containsNumber(Number)
andcontainsRange(Range)
methods. Subclasses may be able to optimise this.- Parameters:
range
- the range to test, may benull
- Returns:
true
if the specified range overlaps with this range; otherwise,false
- Throws:
IllegalArgumentException
- if theRange
cannot be compared
-
equals
public boolean equals(Object obj)
Compares this range to another object to test if they are equal.
.To be equal, the class, minimum and maximum must be equal.
This implementation uses the
getMinimumNumber()
andgetMaximumNumber()
methods. Subclasses may be able to optimise this.
-
hashCode
public int hashCode()
Gets a hashCode for the range.
This implementation uses the
getMinimumNumber()
andgetMaximumNumber()
methods. Subclasses may be able to optimise this.
-
toString
public String toString()
Gets the range as a
String
.The format of the String is 'Range[min,max]'.
This implementation uses the
getMinimumNumber()
andgetMaximumNumber()
methods. Subclasses may be able to optimise this.
-
-