Class NumberRange
- All Implemented Interfaces:
Serializable
NumberRange represents an inclusive range of
Number objects of the same type.
- Since:
- 2.0 (previously in org.apache.commons.lang)
- Version:
- $Id: NumberRange.java 1057072 2011-01-10 01:55:57Z niallp $
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionNumberRange(Number num) Constructs a newNumberRangeusing the specified number as both the minimum and maximum in this range.NumberRange(Number num1, Number num2) Constructs a newNumberRangewith the specified minimum and maximum numbers (both inclusive). -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsNumber(Number number) Tests whether the specifiednumberoccurs within this range.booleanCompares this range to another object to test if they are equal.Returns the maximum number in this range.Returns the minimum number in this range.inthashCode()Gets a hashCode for the range.toString()Gets the range as aString.Methods inherited from class org.apache.commons.lang.math.Range
containsDouble, containsDouble, containsFloat, containsFloat, containsInteger, containsInteger, containsLong, containsLong, containsRange, getMaximumDouble, getMaximumFloat, getMaximumInteger, getMaximumLong, getMinimumDouble, getMinimumFloat, getMinimumInteger, getMinimumLong, overlapsRange
-
Constructor Details
-
NumberRange
Constructs a new
NumberRangeusing the specified number as both the minimum and maximum in this range.- Parameters:
num- the number to use for this range- Throws:
IllegalArgumentException- if the number isnullIllegalArgumentException- if the number doesn't implementComparableIllegalArgumentException- if the number isDouble.NaNorFloat.NaN
-
NumberRange
Constructs a new
NumberRangewith the specified minimum and maximum numbers (both inclusive).The arguments may be passed in the order (min,max) or (max,min). The
getMinimumNumber()andgetMaximumNumber()methods will return the correct value.This constructor is designed to be used with two
Numberobjects of the same type. If two objects of different types are passed in, an exception is thrown.- Parameters:
num1- first number that defines the edge of the range, inclusivenum2- second number that defines the edge of the range, inclusive- Throws:
IllegalArgumentException- if either number isnullIllegalArgumentException- if the numbers are of different typesIllegalArgumentException- if the numbers don't implementComparable
-
-
Method Details
-
getMinimumNumber
Returns the minimum number in this range.
- Specified by:
getMinimumNumberin classRange- Returns:
- the minimum number in this range
-
getMaximumNumber
Returns the maximum number in this range.
- Specified by:
getMaximumNumberin classRange- Returns:
- the maximum number in this range
-
containsNumber
Tests whether the specified
numberoccurs within this range.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- Throws:
IllegalArgumentException- if the number is of a different type to the range
-
equals
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.
-
toString
Gets the range as a
String.The format of the String is 'Range[min,max]'.
-