Package org.jfree.data
Class Range
java.lang.Object
org.jfree.data.Range
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DateRange
Represents an immutable range of values.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate double
The lower bound of the range.private static final long
For serialization.private double
The upper bound of the range. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Range
Creates a new range by combining two existing ranges.static Range
combineIgnoringNaN
(Range range1, Range range2) Returns a new range that spans bothrange1
andrange2
.double
constrain
(double value) Returns the value within the range that is closest to the specified value.boolean
contains
(double value) Returnstrue
if the range contains the specified value andfalse
otherwise.boolean
Tests this object for equality with an arbitrary object.static Range
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 specifiedrange
AND the specifiedvalue
.double
Returns the central value for the range.double
Returns the length of the range.double
Returns the lower bound for the range.double
Returns the upper bound for the range.int
hashCode()
Returns a hash code.boolean
intersects
(double b0, double b1) Returnstrue
if the range intersects with the specified range, andfalse
otherwise.boolean
intersects
(Range range) Returnstrue
if the range intersects with the specified range, andfalse
otherwise.boolean
Returnstrue
if both the lower and upper bounds areDouble.NaN
, andfalse
otherwise.private static double
max
(double d1, double d2) private static double
min
(double d1, double d2) Returns the minimum value.static Range
Scales the range by the specified factor.static Range
Shifts the range by the specified amount.static Range
Shifts the range by the specified amount.private static double
shiftWithNoZeroCrossing
(double value, double delta) Returns the givenvalue
adjusted bydelta
but with a check to prevent the result from crossing0.0
.toString()
Returns a string representation of this Range.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization.- See Also:
-
lower
private double lowerThe lower bound of the range. -
upper
private double upperThe upper bound of the range.
-
-
Constructor Details
-
Range
public Range(double lower, double upper) Creates a new range.- Parameters:
lower
- the lower bound (must be <= upper bound).upper
- the upper bound (must be >= lower bound).
-
-
Method Details
-
getLowerBound
public double getLowerBound()Returns the lower bound for the range.- Returns:
- The lower bound.
-
getUpperBound
public double getUpperBound()Returns the upper bound for the range.- Returns:
- The upper bound.
-
getLength
public double getLength()Returns the length of the range.- Returns:
- The length.
-
getCentralValue
public double getCentralValue()Returns the central value for the range.- Returns:
- The central value.
-
contains
public boolean contains(double value) Returnstrue
if the range contains the specified value andfalse
otherwise.- Parameters:
value
- the value to lookup.- Returns:
true
if the range contains the specified value.
-
intersects
public boolean intersects(double b0, double b1) Returnstrue
if the range intersects with the specified range, andfalse
otherwise.- Parameters:
b0
- the lower bound (should be <= b1).b1
- the upper bound (should be >= b0).- Returns:
- A boolean.
-
intersects
Returnstrue
if the range intersects with the specified range, andfalse
otherwise.- Parameters:
range
- another range (null
not permitted).- Returns:
- A boolean.
-
constrain
public double constrain(double value) Returns the value within the range that is closest to the specified value.- Parameters:
value
- the value.- Returns:
- The constrained value.
-
combine
Creates a new range by combining two existing ranges.Note that:
- either range can be
null
, in which case the other range is returned; - if both ranges are
null
the return value isnull
.
- Parameters:
range1
- the first range (null
permitted).range2
- the second range (null
permitted).- Returns:
- A new range (possibly
null
).
- either range can be
-
combineIgnoringNaN
Returns a new range that spans bothrange1
andrange2
. This method has a special handling to ignore Double.NaN values.- Parameters:
range1
- the first range (null
permitted).range2
- the second range (null
permitted).- Returns:
- A new range (possibly
null
).
-
min
private static double min(double d1, double d2) Returns the minimum value. If either value is NaN, the other value is returned. If both are NaN, NaN is returned.- Parameters:
d1
- value 1.d2
- value 2.- Returns:
- The minimum of the two values.
-
max
private static double max(double d1, double d2) -
expandToInclude
Returns a range that includes all the values in the specifiedrange
AND the specifiedvalue
.- Parameters:
range
- the range (null
permitted).value
- the value that must be included.- Returns:
- A range.
-
expand
Creates a new range by adding margins to an existing range.- Parameters:
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).- Returns:
- The expanded range.
-
shift
Shifts the range by the specified amount.- Parameters:
base
- the base range (null
not permitted).delta
- the shift amount.- Returns:
- A new range.
-
shift
Shifts the range by the specified amount.- Parameters:
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.- Returns:
- A new range.
-
shiftWithNoZeroCrossing
private static double shiftWithNoZeroCrossing(double value, double delta) Returns the givenvalue
adjusted bydelta
but with a check to prevent the result from crossing0.0
.- Parameters:
value
- the value.delta
- the adjustment.- Returns:
- The adjusted value.
-
scale
Scales the range by the specified factor.- Parameters:
base
- the base range (null
not permitted).factor
- the scaling factor (must be non-negative).- Returns:
- A new range.
-
equals
Tests this object for equality with an arbitrary object. -
isNaNRange
public boolean isNaNRange()Returnstrue
if both the lower and upper bounds areDouble.NaN
, andfalse
otherwise.- Returns:
- A boolean.
-
hashCode
public int hashCode()Returns a hash code. -
toString
Returns a string representation of this Range.
-