Class DoubleRange
- java.lang.Object
-
- org.apache.commons.lang.math.Range
-
- org.apache.commons.lang.math.DoubleRange
-
- All Implemented Interfaces:
java.io.Serializable
public final class DoubleRange extends Range implements java.io.Serializable
DoubleRangerepresents an inclusive range ofdoubles.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DoubleRange(double number)Constructs a newDoubleRangeusing the specified number as both the minimum and maximum in this range.DoubleRange(double number1, double number2)Constructs a newDoubleRangewith the specified minimum and maximum numbers (both inclusive).DoubleRange(java.lang.Number number)Constructs a newDoubleRangeusing the specified number as both the minimum and maximum in this range.DoubleRange(java.lang.Number number1, java.lang.Number number2)Constructs a newDoubleRangewith the specified minimum and maximum numbers (both inclusive).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsDouble(double value)Tests whether the specifieddoubleoccurs within this range usingdoublecomparison.booleancontainsNumber(java.lang.Number number)Tests whether the specifiednumberoccurs within this range usingdoublecomparison.booleancontainsRange(Range range)Tests whether the specified range occurs entirely within this range usingdoublecomparison.booleanequals(java.lang.Object obj)Compares this range to another object to test if they are equal.doublegetMaximumDouble()Gets the maximum number in this range as adouble.floatgetMaximumFloat()Gets the maximum number in this range as afloat.intgetMaximumInteger()Gets the maximum number in this range as aint.longgetMaximumLong()Gets the maximum number in this range as along.java.lang.NumbergetMaximumNumber()Returns the maximum number in this range.doublegetMinimumDouble()Gets the minimum number in this range as adouble.floatgetMinimumFloat()Gets the minimum number in this range as afloat.intgetMinimumInteger()Gets the minimum number in this range as aint.longgetMinimumLong()Gets the minimum number in this range as along.java.lang.NumbergetMinimumNumber()Returns the minimum number in this range.inthashCode()Gets a hashCode for the range.booleanoverlapsRange(Range range)Tests whether the specified range overlaps with this range usingdoublecomparison.java.lang.StringtoString()Gets the range as aString.-
Methods inherited from class org.apache.commons.lang.math.Range
containsDouble, containsFloat, containsFloat, containsInteger, containsInteger, containsLong, containsLong
-
-
-
-
Constructor Detail
-
DoubleRange
public DoubleRange(double number)
Constructs a new
DoubleRangeusing the specified number as both the minimum and maximum in this range.- Parameters:
number- the number to use for this range- Throws:
java.lang.IllegalArgumentException- if the number isNaN
-
DoubleRange
public DoubleRange(java.lang.Number number)
Constructs a new
DoubleRangeusing the specified number as both the minimum and maximum in this range.- Parameters:
number- the number to use for this range, must not benull- Throws:
java.lang.IllegalArgumentException- if the number isnulljava.lang.IllegalArgumentException- if the number isNaN
-
DoubleRange
public DoubleRange(double number1, double number2)Constructs a new
DoubleRangewith the specified minimum and maximum numbers (both inclusive).The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
- Parameters:
number1- first number that defines the edge of the range, inclusivenumber2- second number that defines the edge of the range, inclusive- Throws:
java.lang.IllegalArgumentException- if either number isNaN
-
DoubleRange
public DoubleRange(java.lang.Number number1, java.lang.Number number2)Constructs a new
DoubleRangewith the specified minimum and maximum numbers (both inclusive).The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
- Parameters:
number1- first number that defines the edge of the range, inclusivenumber2- second number that defines the edge of the range, inclusive- Throws:
java.lang.IllegalArgumentException- if either number isnulljava.lang.IllegalArgumentException- if either number isNaN
-
-
Method Detail
-
getMinimumNumber
public java.lang.Number getMinimumNumber()
Returns the minimum number in this range.
- Specified by:
getMinimumNumberin classRange- Returns:
- the minimum number in this range
-
getMinimumLong
public long getMinimumLong()
Gets the minimum number in this range as a
long.This conversion can lose information for large values or decimals.
- Overrides:
getMinimumLongin classRange- Returns:
- the minimum number in this range
-
getMinimumInteger
public int getMinimumInteger()
Gets the minimum number in this range as a
int.This conversion can lose information for large values or decimals.
- Overrides:
getMinimumIntegerin classRange- Returns:
- the minimum number in this range
-
getMinimumDouble
public double getMinimumDouble()
Gets the minimum number in this range as a
double.- Overrides:
getMinimumDoublein classRange- Returns:
- the minimum number in this range
-
getMinimumFloat
public float getMinimumFloat()
Gets the minimum number in this range as a
float.This conversion can lose information for large values.
- Overrides:
getMinimumFloatin classRange- Returns:
- the minimum number in this range
-
getMaximumNumber
public java.lang.Number getMaximumNumber()
Returns the maximum number in this range.
- Specified by:
getMaximumNumberin classRange- Returns:
- the maximum number in this range
-
getMaximumLong
public long getMaximumLong()
Gets the maximum number in this range as a
long.This conversion can lose information for large values or decimals.
- Overrides:
getMaximumLongin classRange- Returns:
- the maximum number in this range
-
getMaximumInteger
public int getMaximumInteger()
Gets the maximum number in this range as a
int.This conversion can lose information for large values or decimals.
- Overrides:
getMaximumIntegerin classRange- Returns:
- the maximum number in this range
-
getMaximumDouble
public double getMaximumDouble()
Gets the maximum number in this range as a
double.- Overrides:
getMaximumDoublein classRange- Returns:
- the maximum number in this range
-
getMaximumFloat
public float getMaximumFloat()
Gets the maximum number in this range as a
float.This conversion can lose information for large values.
- Overrides:
getMaximumFloatin classRange- Returns:
- the maximum number in this range
-
containsNumber
public boolean containsNumber(java.lang.Number number)
Tests whether the specified
numberoccurs within this range usingdoublecomparison.nullis handled and returnsfalse.- Specified by:
containsNumberin classRange- Parameters:
number- the number to test, may benull- Returns:
trueif the specified number occurs within this range
-
containsDouble
public boolean containsDouble(double value)
Tests whether the specified
doubleoccurs within this range usingdoublecomparison.This implementation overrides the superclass for performance as it is the most common case.
- Overrides:
containsDoublein classRange- Parameters:
value- the double to test- Returns:
trueif the specified number occurs within this range bydoublecomparison
-
containsRange
public boolean containsRange(Range range)
Tests whether the specified range occurs entirely within this range using
doublecomparison.nullis handled and returnsfalse.- Overrides:
containsRangein classRange- Parameters:
range- the range to test, may benull- Returns:
trueif the specified range occurs entirely within this range- Throws:
java.lang.IllegalArgumentException- if the range is not of this type
-
overlapsRange
public boolean overlapsRange(Range range)
Tests whether the specified range overlaps with this range using
doublecomparison.nullis handled and returnsfalse.- Overrides:
overlapsRangein classRange- Parameters:
range- the range to test, may benull- Returns:
trueif the specified range overlaps with this range
-
equals
public boolean equals(java.lang.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.
-
hashCode
public int hashCode()
Gets a hashCode for the range.
-
-