org.apache.commons.lang
Class NumberRange

java.lang.Object
  |
  +--org.apache.commons.lang.NumberRange

public final class NumberRange
extends java.lang.Object

Represents a range of Number objects.

Version:
$Revision: 1.1.2.1 $ $Date: 2002/11/22 23:20:28 $
Author:
Christopher Elkins, Stephen Colebourne

Field Summary
private  java.lang.Number max
           
private  java.lang.Number min
           
 
Constructor Summary
NumberRange(java.lang.Number num)
          Constructs a new instance using the specified number as both the minimum and maximum in theis range.
NumberRange(java.lang.Number min, java.lang.Number max)
          Constructs a new instance with the specified minimum and maximum numbers.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal" to this one.
 java.lang.Number getMaximum()
          Returns the maximum number in this range.
 java.lang.Number getMinimum()
          Returns the minimum number in this range.
 int hashCode()
          Returns a hash code value for this object.
 boolean includesNumber(java.lang.Number number)
          Tests whether the specified number occurs within this range.
 boolean includesRange(NumberRange range)
          Tests whether the specified range occurs entirely within this range.
 boolean overlaps(NumberRange range)
          Tests whether the specified range overlaps with this range.
 java.lang.String toString()
          Returns the string representation of this range.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

min

private final java.lang.Number min

max

private final java.lang.Number max
Constructor Detail

NumberRange

public NumberRange(java.lang.Number num)
Constructs a new instance using the specified number as both the minimum and maximum in theis range.
Parameters:
num - the number to use for this range
Throws:
NullPointerException - if the number is null

NumberRange

public NumberRange(java.lang.Number min,
                   java.lang.Number max)
Constructs a new instance with the specified minimum and maximum numbers.
Parameters:
min - the minimum number in this range
max - the maximum number in this range
Throws:
NullPointerException - if either the minimum or maximum number is null
Method Detail

getMinimum

public java.lang.Number getMinimum()
Returns the minimum number in this range.
Returns:
the minimum number in this range

getMaximum

public java.lang.Number getMaximum()
Returns the maximum number in this range.
Returns:
the maximum number in this range

includesNumber

public boolean includesNumber(java.lang.Number number)
Tests whether the specified number occurs within this range.
Parameters:
number - the number to test
Returns:
true if the specified number occurs within this range; otherwise, false

includesRange

public boolean includesRange(NumberRange range)
Tests whether the specified range occurs entirely within this range.
Parameters:
range - the range to test
Returns:
true if the specified range occurs entirely within this range; otherwise, false

overlaps

public boolean overlaps(NumberRange range)
Tests whether the specified range overlaps with this range.
Parameters:
range - the range to test
Returns:
true if the specified range overlaps with this range; otherwise, false

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal" to this one.
Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference object with which to compare
Returns:
true if this object is the same as the obj argument; false otherwise

hashCode

public int hashCode()
Returns a hash code value for this object.
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object

toString

public java.lang.String toString()
Returns the string representation of this range. This string is the string representation of the minimum and maximum numbers in the range, separated by a hyphen. If a number is negative, then it is enclosed in parentheses.
Overrides:
toString in class java.lang.Object
Returns:
the string representation of this range


Copyright (c) 2001-2002 - Apache Software Foundation