public class Range extends java.lang.Object implements java.lang.Comparable<Range>, java.io.Serializable
Note: If a range is constructed where the upper and lower bounds are equal and one of them is exclusive, this range is considered empty, i.e. no number can be contained in it.
Constructor and Description |
---|
Range(double lowerBound,
boolean lowerIsInclusive,
double upperBound,
boolean upperIsInclusive)
Create range.
|
Range(double lower,
double upper)
Create range where both bounds are inclusive.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Range other) |
boolean |
contains(double number)
Checks is a number is contained in the range.
|
boolean |
contains(Range other)
Determines whether the other range is fully contained in this range.
|
boolean |
equals(java.lang.Object obj)
Two ranges are equal if their bounds are equal and the flags that indicate if
the bounds are inclusive or not are equal, too.
|
java.lang.String |
format(java.text.NumberFormat numberFormat)
String representation contains the bounds and brackets that indicate if the
bounds are inclusive or exclusive.
|
double |
getLower()
Get lower bound.
|
double |
getUpper()
Get upper bound.
|
int |
hashCode()
Hash code includes bound and the flags that indicate if the bounds are
inclusive or not.
|
boolean |
isEmpty()
Checks if a range is empty.
|
boolean |
isLowerInclusive()
Get flag that indicates if the lower bound is inclusive.
|
boolean |
isSingleton()
Returns whether this range is a singleton (i.e.
|
boolean |
isUpperInclusive()
Get flag that indicates if the upper bound is inclusive.
|
boolean |
overlaps(Range other)
Returns whether this range has a non-empty intersection with another range.
|
double |
size()
Returns the size of the range.
|
java.lang.String |
toString()
This forwards to
format(null); . |
Range |
union(Range other)
Calculates the union of this range with another range.
|
public Range(double lower, double upper)
public Range(double lowerBound, boolean lowerIsInclusive, double upperBound, boolean upperIsInclusive)
lowerIsInclusive
- flag that indicates if lower bound is inclusive or notupperIsInclusive
- flag that indicates if upper bound is inclusive or notpublic boolean contains(double number)
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public double getLower()
public double getUpper()
public boolean isLowerInclusive()
public boolean isUpperInclusive()
public boolean isEmpty()
public boolean isSingleton()
public double size()
public java.lang.String toString()
format(null);
.toString
in class java.lang.Object
public java.lang.String format(java.text.NumberFormat numberFormat)
numberFormat
- number format used for formatting the numbers. If this is
null
, no special formatting is applied.public boolean overlaps(Range other)
public int compareTo(Range other)
Compares by lower values.
compareTo
in interface java.lang.Comparable<Range>
public boolean contains(Range other)