public class NumberRange extends Range
Note, many methods in this particular class have the same signatures as in the apache commons.lang package but the implementation was strictly clean-room.
Thread Safety: This class is not thread safe in the face of any concurrent modification (via changing the start/end numbers or union/intersection operations).
Constructor and Description |
---|
NumberRange(long start,
long end)
Constructs a number range between the specified
start and end numbers (both inclusive).
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
long |
getEnd()
Get the end number for this number range.
|
long |
getSize()
Returns the size of this range which is calculated as the
(endnumber - startnumber) + 1 - i.e., the number of
slots in this range, start and end inclusive.
|
long |
getStart()
Get the start number for this number range
|
int |
hashCode() |
boolean |
inRange(long c)
Is the passed in number inside this range
|
static void |
main(java.lang.String[] args) |
void |
setEnd(long c)
Sets the end number for this number range
|
void |
setStart(long c)
Set the start number for this number range
|
java.lang.String |
toString()
Output a string representation of the number range
|
isNegated, setNegated
public NumberRange(long start, long end)
java.lang.IllegalArgumentException
- if the end number is lesser (via a < comparison)
than the start number (equal to the start number is ok)public long getStart()
public long getEnd()
public boolean inRange(long c)
public void setEnd(long c)
c
- the end numberjava.lang.IllegalArgumentException
- if the end number is lesser (via a < comparison)
than the current start number (equal to the start number is
ok)public void setStart(long c)
java.lang.IllegalArgumentException
- if the start number is greater (via a > comparison)
than the current end number (equal to the end number is
ok)public long getSize()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static void main(java.lang.String[] args)