org.apache.commons.lang.math
public final class NumberRange extends Range implements Serializable
NumberRange
represents an inclusive range of
java.lang.Number objects of the same type.
Since: 2.0 (previously in org.apache.commons.lang)
Version: $Id: NumberRange.java 437554 2006-08-28 06:21:41Z bayard $
Constructor Summary | |
---|---|
NumberRange(Number num) Constructs a new | |
NumberRange(Number num1, Number num2) Constructs a new The arguments may be passed in the order (min,max) or (max,min). |
Method Summary | |
---|---|
boolean | containsNumber(Number number) Tests whether the specified
|
boolean | equals(Object obj) Compares this range to another object to test if they are equal. . |
Number | getMaximumNumber() Returns the maximum number in this range. |
Number | getMinimumNumber() Returns the minimum number in this range. |
int | hashCode() Gets a hashCode for the range. |
String | toString() Gets the range as a The format of the String is 'Range[min,max]'. |
Constructs a new NumberRange
using 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 is null
IllegalArgumentException if the number doesn't implement Comparable
IllegalArgumentException if the number is Double.NaN
or Float.NaN
Constructs a new NumberRange
with the specified
minimum and maximum numbers (both inclusive).
The arguments may be passed in the order (min,max) or (max,min). The getMinimumNumber and getMaximumNumber methods will return the correct value.
This constructor is designed to be used with two Number
objects 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, inclusive num2 second number that defines the edge of the range, inclusive
Throws: IllegalArgumentException if either number is null
IllegalArgumentException if the numbers are of different types IllegalArgumentException if the numbers don't implement Comparable
Tests whether the specified number
occurs within
this range.
null
is handled and returns false
.
Parameters: number the number to test, may be null
Returns: true
if the specified number occurs within this range
Throws: IllegalArgumentException if the number is of a different type to the range
Compares this range to another object to test if they are equal.
.To be equal, the class, minimum and maximum must be equal.
Parameters: obj the reference object with which to compare
Returns: true
if this object is equal
Returns the maximum number in this range.
Returns: the maximum number in this range
Returns the minimum number in this range.
Returns: the minimum number in this range
Gets a hashCode for the range.
Returns: a hash code value for this object
Gets the range as a String
.
The format of the String is 'Range[min,max]'.
Returns: the String
representation of this range