|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jstatcom.model.NumberRange
public final class NumberRange
This class specifies an interval defined by two numbers and a type and
provides methods to validate numbers and other NumberRange
instances against it.
The class is immutable by design, see (Joshua Bloch, "Effective Java", Item 13).
Field Summary | |
---|---|
double |
lowerBound
The lower bound of this range. |
NumberRangeTypes |
rangeType
The type of this range, which is either OPEN, CLOSED, LEFT_OPEN or RIGHT_OPEN . |
double |
upperBound
The upper bound of this range. |
Constructor Summary | |
---|---|
NumberRange()
Creates an open range with (-Infinity,+Infinity) . |
|
NumberRange(double lowerBoundNew,
double upperBoundNew,
NumberRangeTypes rangeType)
Creates a range according to the given bounds and the type. |
Method Summary | |
---|---|
double |
defaultNumber()
Finds a number that is valid for this range. |
NumberRange |
defaultNumberRange()
Finds a number range that is enclosed by this range. |
java.lang.String |
encloses(double number)
Tests whether a given number is enclosed in this range and returns a formatted message if not. |
java.lang.String |
encloses(double number,
int precision,
java.text.NumberFormat formatter)
Tests whether a given number is enclosed in this range and returns a formatted message if not. |
java.lang.String |
encloses(NumberRange numberRange)
Tests whether a given range is completely enclosed within this range and returns a formatted message if not. |
boolean |
equals(java.lang.Object o)
Provides logical equals check. |
java.lang.String |
formattedString(java.text.NumberFormat formatter)
Gets a string representation of this range with a special formatter. |
int |
hashCode()
Overrides hashCode , because equals was overwritten. |
double |
lowerBound()
Gets the lower bound for this range. |
java.lang.String |
toString()
Gets string representation of this range. |
NumberRangeTypes |
type()
Gets the interval type for this range. |
double |
upperBound()
Gets the upper bound for this range. |
static NumberRange |
valueOf(java.lang.String exp)
Static initialized that creates a NumberRange from a
string representation. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final double lowerBound
public final double upperBound
public final NumberRangeTypes rangeType
OPEN, CLOSED, LEFT_OPEN or RIGHT_OPEN
.
Constructor Detail |
---|
public NumberRange()
(-Infinity,+Infinity)
.
public NumberRange(double lowerBoundNew, double upperBoundNew, NumberRangeTypes rangeType)
lowerBoundNew
- the lower bound of the intervalupperBoundNew
- the upper bound of the intervalrangeType
- the interval type to be created
java.lang.IllegalArgumentException
- if:
- lowerBound > upperBound
- lowerBound == upperBound and rangeType is not closed
- lowerBound == -Infinity and rangeType is not left open
- upperBound == +Infinity and rangeType is not right open
- lowerBound == +Infinity
- upperBound == -Infinity
- upperBound or lowerBound is equal to NaN
- rangeType == null
Method Detail |
---|
public double defaultNumber()
public NumberRange defaultNumberRange()
CLOSED
.
public java.lang.String encloses(double number)
number
- the value to check
number
is contained, message if notpublic java.lang.String encloses(double number, int precision, java.text.NumberFormat formatter)
number
before checking. If the
number is either POS_INF, NEG_INF or NaN, it is never enclosed in the
range.
number
- the value to checkprecision
- the number of digits right to the decimal point to take into
account for checkingformatter
- a formatter for number
in the possible error
message, can be null
number
is contained, message if not
java.lang.IllegalArgumentException
- if if (precision < 0)
public java.lang.String encloses(NumberRange numberRange)
numberRange
- the range to check
numberRange
is contained, message if notpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- another range to compare with
true
if lower bound, upper bound and range type
are all equalpublic java.lang.String formattedString(java.text.NumberFormat formatter)
formatter == null
, this is identical to
toString
.
formatter
- a number formatter for the bounds, can be null
public double lowerBound()
public NumberRangeTypes type()
public double upperBound()
public int hashCode()
hashCode
, because equals was overwritten. The
algorithm was taken from (Joshua Bloch, "Effective Java", Item 8).
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static NumberRange valueOf(java.lang.String exp)
NumberRange
from a
string representation. Valid expressions are:
- [1,100]
- (-Infinity,100.3]
- (-Infinity,+Infinity)
- (-12E-2,23]
- [100,100]
exp
- string containing a valid representation for a number range
exp
java.lang.IllegalArgumentException
- if exp
could not be parsed to a valid number
rangeNumberRange(double lowerBoundNew,double
upperBoundNew,NumberRangeTypes rangeType)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |