Represents an immutable range of values.
| Method from org.jfree.data.Range Detail: |
public static Range combine(Range range1,
Range range2) {
if (range1 == null) {
return range2;
}
else {
if (range2 == null) {
return range1;
}
else {
double l = Math.min(range1.getLowerBound(),
range2.getLowerBound());
double u = Math.max(range1.getUpperBound(),
range2.getUpperBound());
return new Range(l, u);
}
}
}
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 is
null.
|
public double constrain(double value) {
double result = value;
if (!contains(value)) {
if (value > this.upper) {
result = this.upper;
}
else if (value < this.lower) {
result = this.lower;
}
}
return result;
}
Returns the value within the range that is closest to the specified
value. |
public boolean contains(double value) {
return (value >= this.lower && value < = this.upper);
}
Returns true if the range contains the specified value and
false otherwise. |
public boolean equals(Object obj) {
if (!(obj instanceof Range)) {
return false;
}
Range range = (Range) obj;
if (!(this.lower == range.lower)) {
return false;
}
if (!(this.upper == range.upper)) {
return false;
}
return true;
}
Tests this object for equality with an arbitrary object. |
public static Range expand(Range range,
double lowerMargin,
double upperMargin) {
if (range == null) {
throw new IllegalArgumentException("Null 'range' argument.");
}
double length = range.getLength();
double lower = range.getLowerBound() - length * lowerMargin;
double upper = range.getUpperBound() + length * upperMargin;
if (lower > upper) {
lower = lower / 2.0 + upper / 2.0;
upper = lower;
}
return new Range(lower, upper);
}
Creates a new range by adding margins to an existing range. |
public static Range expandToInclude(Range range,
double value) {
if (range == null) {
return new Range(value, value);
}
if (value < range.getLowerBound()) {
return new Range(value, range.getUpperBound());
}
else if (value > range.getUpperBound()) {
return new Range(range.getLowerBound(), value);
}
else {
return range;
}
}
Returns a range that includes all the values in the specified
range AND the specified value. |
public double getCentralValue() {
return this.lower / 2.0 + this.upper / 2.0;
}
Returns the central value for the range. |
public double getLength() {
return this.upper - this.lower;
}
Returns the length of the range. |
public double getLowerBound() {
return this.lower;
}
Returns the lower bound for the range. |
public double getUpperBound() {
return this.upper;
}
Returns the upper bound for the range. |
public int hashCode() {
int result;
long temp;
temp = Double.doubleToLongBits(this.lower);
result = (int) (temp ^ (temp > > > 32));
temp = Double.doubleToLongBits(this.upper);
result = 29 * result + (int) (temp ^ (temp > > > 32));
return result;
}
|
public boolean intersects(Range range) {
return intersects(range.getLowerBound(), range.getUpperBound());
}
Returns true if the range intersects with the specified
range, and false otherwise. |
public boolean intersects(double b0,
double b1) {
if (b0 < = this.lower) {
return (b1 > this.lower);
}
else {
return (b0 < this.upper && b1 >= b0);
}
}
Returns true if the range intersects with the specified
range, and false otherwise. |
public static Range scale(Range base,
double factor) {
if (base == null) {
throw new IllegalArgumentException("Null 'base' argument.");
}
if (factor < 0) {
throw new IllegalArgumentException("Negative 'factor' argument.");
}
return new Range(base.getLowerBound() * factor,
base.getUpperBound() * factor);
}
Scales the range by the specified factor. |
public static Range shift(Range base,
double delta) {
return shift(base, delta, false);
}
Shifts the range by the specified amount. |
public static Range shift(Range base,
double delta,
boolean allowZeroCrossing) {
if (base == null) {
throw new IllegalArgumentException("Null 'base' argument.");
}
if (allowZeroCrossing) {
return new Range(base.getLowerBound() + delta,
base.getUpperBound() + delta);
}
else {
return new Range(shiftWithNoZeroCrossing(base.getLowerBound(),
delta), shiftWithNoZeroCrossing(base.getUpperBound(),
delta));
}
}
Shifts the range by the specified amount. |
public String toString() {
return ("Range[" + this.lower + "," + this.upper + "]");
}
Returns a string representation of this Range. |