Class NumberRange
- java.lang.Object
-
- org.apache.commons.lang.math.Range
-
- org.apache.commons.lang.math.NumberRange
-
- All Implemented Interfaces:
java.io.Serializable
public final class NumberRange extends Range implements java.io.Serializable
NumberRangerepresents an inclusive range ofNumberobjects of the same type.- Since:
- 2.0 (previously in org.apache.commons.lang)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description NumberRange(java.lang.Number num)Constructs a newNumberRangeusing the specified number as both the minimum and maximum in this range.NumberRange(java.lang.Number num1, java.lang.Number num2)Constructs a newNumberRangewith the specified minimum and maximum numbers (both inclusive).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsNumber(java.lang.Number number)Tests whether the specifiednumberoccurs within this range.booleanequals(java.lang.Object obj)Compares this range to another object to test if they are equal.java.lang.NumbergetMaximumNumber()Returns the maximum number in this range.java.lang.NumbergetMinimumNumber()Returns the minimum number in this range.inthashCode()Gets a hashCode for the range.java.lang.StringtoString()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 Detail
-
NumberRange
public NumberRange(java.lang.Number num)
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:
java.lang.IllegalArgumentException- if the number isnulljava.lang.IllegalArgumentException- if the number doesn't implementComparablejava.lang.IllegalArgumentException- if the number isDouble.NaNorFloat.NaN
-
NumberRange
public NumberRange(java.lang.Number num1, java.lang.Number num2)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:
java.lang.IllegalArgumentException- if either number isnulljava.lang.IllegalArgumentException- if the numbers are of different typesjava.lang.IllegalArgumentException- if the numbers don't implementComparable
-
-
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
-
getMaximumNumber
public java.lang.Number getMaximumNumber()
Returns the maximum number in this range.
- Specified by:
getMaximumNumberin classRange- Returns:
- the maximum number in this range
-
containsNumber
public boolean containsNumber(java.lang.Number number)
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:
java.lang.IllegalArgumentException- if the number is of a different type to the 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.
-
-