public class Range extends java.lang.Object implements java.io.Serializable
Constructor and Description |
---|
Range(double lower,
double upper)
Creates a new range.
|
Modifier and Type | Method and Description |
---|---|
static Range |
combine(Range range1,
Range range2)
Creates a new range by combining two existing ranges.
|
static Range |
combineIgnoringNaN(Range range1,
Range range2)
Returns a new range that spans both
range1 and
range2 . |
double |
constrain(double value)
Returns the value within the range that is closest to the specified
value.
|
boolean |
contains(double value)
Returns
true if the range contains the specified value and
false otherwise. |
boolean |
equals(java.lang.Object obj)
Tests this object for equality with an arbitrary object.
|
static Range |
expand(Range range,
double lowerMargin,
double upperMargin)
Creates a new range by adding margins to an existing range.
|
static Range |
expandToInclude(Range range,
double value)
Returns a range that includes all the values in the specified
range AND the specified value . |
double |
getCentralValue()
Returns the central value for the range.
|
double |
getLength()
Returns the length of the range.
|
double |
getLowerBound()
Returns the lower bound for the range.
|
double |
getUpperBound()
Returns the upper bound for the range.
|
int |
hashCode()
Returns a hash code.
|
boolean |
intersects(double b0,
double b1)
Returns
true if the range intersects with the specified
range, and false otherwise. |
boolean |
intersects(Range range)
Returns
true if the range intersects with the specified
range, and false otherwise. |
boolean |
isNaNRange()
Returns
true if both the lower and upper bounds are
Double.NaN , and false otherwise. |
static Range |
scale(Range base,
double factor)
Scales the range by the specified factor.
|
static Range |
shift(Range base,
double delta)
Shifts the range by the specified amount.
|
static Range |
shift(Range base,
double delta,
boolean allowZeroCrossing)
Shifts the range by the specified amount.
|
java.lang.String |
toString()
Returns a string representation of this Range.
|
public Range(double lower, double upper)
lower
- the lower bound (must be <= upper bound).upper
- the upper bound (must be >= lower bound).public double getLowerBound()
public double getUpperBound()
public double getLength()
public double getCentralValue()
public boolean contains(double value)
true
if the range contains the specified value and
false
otherwise.value
- the value to lookup.true
if the range contains the specified value.public boolean intersects(double b0, double b1)
true
if the range intersects with the specified
range, and false
otherwise.b0
- the lower bound (should be <= b1).b1
- the upper bound (should be >= b0).public boolean intersects(Range range)
true
if the range intersects with the specified
range, and false
otherwise.range
- another range (null
not permitted).public double constrain(double value)
value
- the value.public static Range combine(Range range1, Range range2)
Note that:
null
, in which case the other
range is returned;null
the return value is
null
.range1
- the first range (null
permitted).range2
- the second range (null
permitted).null
).public static Range combineIgnoringNaN(Range range1, Range range2)
range1
and
range2
. This method has a special handling to ignore
Double.NaN values.range1
- the first range (null
permitted).range2
- the second range (null
permitted).null
).public static Range expandToInclude(Range range, double value)
range
AND the specified value
.range
- the range (null
permitted).value
- the value that must be included.public static Range expand(Range range, double lowerMargin, double upperMargin)
range
- the range (null
not permitted).lowerMargin
- the lower margin (expressed as a percentage of the
range length).upperMargin
- the upper margin (expressed as a percentage of the
range length).public static Range shift(Range base, double delta)
base
- the base range (null
not permitted).delta
- the shift amount.public static Range shift(Range base, double delta, boolean allowZeroCrossing)
base
- the base range (null
not permitted).delta
- the shift amount.allowZeroCrossing
- a flag that determines whether or not the
bounds of the range are allowed to cross
zero after adjustment.public static Range scale(Range base, double factor)
base
- the base range (null
not permitted).factor
- the scaling factor (must be non-negative).public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object to test against (null
permitted).public boolean isNaNRange()
true
if both the lower and upper bounds are
Double.NaN
, and false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object