public class Range
extends java.lang.Object
implements java.lang.Comparable
Long
numbers between a lower bound
and an upper bound (inclusive).Modifier and Type | Field and Description |
---|---|
private java.lang.Long |
lowerBound
Lower bound of range.
|
private java.lang.Long |
upperBound
Upper bound of range.
|
Constructor and Description |
---|
Range()
Creates an empty range.
|
Range(long number)
Creates a new range representing a single number.
|
Range(long lowerBound,
long upperBound)
Creates a new range object.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(java.lang.Object o)
Compares this object with the specified object for order.
|
boolean |
contains(long number)
Returns
true if the specified number is contained in the
range. |
java.lang.Long |
extractFirstNumber()
Returns the fisrt number in range AND removes it from range.
|
java.lang.Long |
getLowerBound()
Get the lower bound.
|
java.lang.Long |
getRangeSize()
Return the quantity of numbers in range.
|
java.lang.Long |
getUpperBound()
Get the upper bound.
|
boolean |
isEmpty()
Determines whether this range is empty (contains no numbers).
|
static void |
main(java.lang.String[] args)
Main function for testing purposes.
|
void |
makeEmpty()
Makes this range empty.
|
void |
setBounds(long lowerBound,
long upperBound)
Sets lower and upper bound of range.
|
java.util.List<Range> |
splitRange(java.util.List<java.lang.Long> numbers)
Splits the range into several ranges using the given numbers as break
points.
|
java.util.List<Range> |
splitRange(java.util.SortedSet<java.lang.Long> numbers)
Splits the range into several ranges using the given numbers as break
points.
|
java.lang.String |
toString()
Return string representation of the range.
|
private java.lang.Long lowerBound
private java.lang.Long upperBound
public Range()
public Range(long lowerBound, long upperBound)
lowerBound
- Lower bound of range.upperBound
- Upper bound of range.public Range(long number)
number
- Number to represent.public java.lang.Long getLowerBound()
public java.lang.Long getUpperBound()
public java.lang.Long getRangeSize()
public void setBounds(long lowerBound, long upperBound)
lowerBound
- Lower bound of range.upperBound
- Upper bound of range.public boolean isEmpty()
true
if this range contain an least one number.
false
otherwise.public void makeEmpty()
public boolean contains(long number)
true
if the specified number is contained in the
range.number
- Number to be checked for containment in this range.true
if the specified number is contained in the
range.public java.lang.Long extractFirstNumber()
null
if the range
contatins no numbers.public java.util.List<Range> splitRange(java.util.SortedSet<java.lang.Long> numbers)
numbers
- Break points for splitting.public java.util.List<Range> splitRange(java.util.List<java.lang.Long> numbers)
numbers
- Break points for splitting. Should be sorted in ascending order.public java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
o
- The object to be compared.public static void main(java.lang.String[] args)
args
- Not used.